If you want to ZIP the packages yourself, you can do the following commands
zip -j your_lambda_code.zip your_lambda_code/*
for i in $(find code/* -type d -d 0); do zip -jr "${i%/}.zip" "$i"; done
sam package --profile *yourprofile* --region *yourregion* --template-file template.yaml --s3-bucket *yourbucket* --output-template packaged.yaml
sam deploy --profile yourprofile --template-file packaged.yaml --region yourregion --capabilities CAPABILITY_IAM --stack-name name_of_your_stack
With the -u command the functions will be build with a docker similar to the AWS
sam build -u
Now we can also invoke the functions locally
sam local generate-event sqs receive-message > SqsEvent.json
sam local invoke SubmitVerdictFunction -e SqsEvent.json
sam local start-api
The folder structure needs to look like this
.
└── yourlayer/
└── python/
└── script_to_import.py
In the SAM template: Reference the FOLDER, not the zip Define the layer in your SAM template
MyLayer:
Type: AWS::Serverless::LayerVersion
Properties:
LayerName: layerExample
Description: Layer to do cool stuff
ContentUri: my_layer_folder/
CompatibleRuntimes:
- python3.6
- python2.7
LicenseInfo: MIT
RetentionPolicy: retain
This can be referenced in a function with (YAML style) in your Function:
Layers:
- !Ref layerExample
Put it in a ZIP file, while in the layer/ folder with the python sub directory
zip -r myname_layer.zip ./python/
Policies:
- Statement:
- Sid: SSMDescribeParametersPolicy
Effect: Allow
Action:
- ssm:DescribeParameters
Resource: '*'
- Sid: SSMGetParameterPolicy
Effect: Allow
Action:
- ssm:GetParameters
- ssm:GetParameter
Resource: '*'