0
votes

When I manually create a Lambda Layer I add all the code inside the "python" folder as required, zip that folder, upload it and everything works.

However, when I used Serverless (SLS), it correctly packages everything inside a "python.zip", but when I deploy the package folder is suddenly called "python-[HASH]". As a result, I cannot import the python dependencies from that layer.

Why is there this hash? Is there a better way to deal with custom packages that are shared across Lambda functions?

1

1 Answers

0
votes

So it depends on how you package your function, below is my SAM template for function and the corresponding lambda layer :

    HelloWorldFunction:
        Type: AWS::Serverless::Functionn
        Properties:
        CodeUri: hello_world/
        Handler: app.lambda_handler
        Runtime: python3.8
        Role: !GetAtt LambdaRole.Arn
        Layers:
            - !Ref MyLambdaLayer

    MyLambdaLayer:
            Type: AWS::Serverless::LayerVersion
            Properties:
                LayerName: MyLambdaLayer
                ContentUri: lambda-layer/
                CompatibleRuntimes:
                - python3.8
                RetentionPolicy: Retain

And my directory structure for the packaging is:

.
├── README.md
├── hello_world
│   ├── app.py
│   └── requirements.txt
├── lambda-layer
│   └── python
│       └── lib
│           └── python3.8
│               └── site-packages
│                   └── hello.py
├── samconfig.toml
└── template.yaml