- Neueste
- Die meisten Stimmen
- Die meisten Kommentare
Thank you for your feedback. The reason that the Lambda Layer which you create through the Lambda console is deleted upon deployments is because the Lambda functions are managed by your project's CloudFormation stack. Any changes performed outside of the stack will be overwritten when that stack is deployed again.
If you'd like to create a Lambda Layer within your project, it is best to use the AWS::Lambda::LayerVersion CloudFormation resource to do so https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-layerversion.html. You will also need to update your existing Lambda function resource to reference the new Layer https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-lambda-function.html#cfn-lambda-function-layers.
However, Lambda Layers may not work the best for your use-case, as source code changes will not update an existing Lambda Layer, so a new Layer has to be created each time you make changes to your code. Instead, we recommend that your two Lambda functions be located within the same code base and reuse code directly from within the repository. Let me know if you are still confused or if this does not work for you.
hello, robsondepaula.
I faced same situation.
I wanted to re-use common codes in lambdas, and manage them codecommit and cloudformation.
I thought it can achieve making lambda layer.
But I gave up because to make lambda layer, I need to upload source code S3.
Now, I usually do following way to achieve that.
your_project---- lambda1 -- lambda1_code.py
|
|--- lambda2 -- lambda2_code.py
|
---- common_modules -- common_module.py
Then, write this in buildspec.yml before do aws cloudformation package(maybe install phase is better?)
- cp ./common_modules/common_module.py ./lambda1/
- cp ./common_modules/common_module.py ./lambda2/
In this way, it performs likes lambda layer, and it can be managed by codecommit and cloudformation.
For your information.
Relevanter Inhalt
- AWS OFFICIALAktualisiert vor 6 Monaten
- AWS OFFICIALAktualisiert vor 2 Jahren