0

I am working in PyCharm with the AWS SAM and AWS SAM CLI modules. I am trying to setup a simple program:

  1. An Amazon Lambda layer for "ROCFacade"
  2. ROCFacade will import Python's standard requests module. After installing it with PIP, I copied it from the External Libraries/python3.8/site-packages folder (third box) to the lambda-layers subfolder in the second box.
  3. I am trying to call it from hello-world/app.py which so far is little more than the boilerplate installed by AWS SAM

When I try to run it, PyCharm reports that the ROCFacade module cannot be found.

Folder structure

The error message occurs if I ran it with an "app" configuration or with the Lambda configuration, below.

I have another project that uses the same ROCFacade with a simple main.py console app so the code does work. I'm not sure if my problem here is with environment variables (i.e., Python doesn't know to look in the lambda-layers folder) or the Pythong app/Lambda configuration. I am a newbie to both Python and Lambda/AWS development.

Thank you

Lambda error message

Lambda configuration

1 Answer 1

0

I found my oversight. In the template.yaml the dev needs to add a reference to the layer in the function descriptor and define the layer.

Resources:
  HelloWorldFunction:
    Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
    Properties:
      CodeUri: hello_world/
      Handler: app.lambda_handler
      Runtime: python3.8
      Layers: !Ref ROCFacadeLayer
      Events:
        HelloWorld:
          Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
          Properties:
            Path: /hello
            Method: get

ROCFacadeLayer:
  Type: AWS::Serverless::LayerVersion
  Properties:
    LayerName: ROCFacadeLayer
    ContentUri: lambda-layers/roc-facade-layer.zip
    CompatibleRuntimes:
      - python3.7
      - python3.8
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.