2021年4月30日星期五

How to add a dependency file in AWS Lambda Console with CloudFormation Package

My AWS lambda function MyLambda requires a file called auxiliary.json. I manually created the function and the file in the console and it is working fine.

Now, I would like to do this using CloudFormation so that I can see both the lambda function code and the file content on the console, and it works the same way it does with the manually created one. I do not want to package it with as zip and push it to S3 bucket.

I have the files in my code folder in the following structure:

.  ├── lambda-template.yaml  └── lambdas/      ├── mylambda.py      └── auxiliary.json  

In lambda-template.yaml, I have the lambda resource like below:

Resources:    MyLambda:      Type: AWS::Lambda::Function      Properties:              FunctionName: "MyLambda"        Code: lambdas/mylambda.py        Handler: "MyLambda.lambda_handler"        Runtime: "python3.8"        Timeout: 30        MemorySize: 128  

After running the aws cloudformation package like below, I get the code from mylambda.py added to mylambda-template.packaged.yaml file.

aws cloudformation package \     --template-file mylambda-template.yaml \     --s3-bucket example-bucket \     --output-template-file mylambda-template.packaged.yaml \     --profile myawsprofile \     --region us-east-1  

And, I can deploy the packaged template like below with no issue:

aws cloudformation deploy \     --template-file mylambda-template.packaged.yaml \     --stack-name mylambda \     --profile myawsprofile \     --region us-east-1  

However, I cannot take add the required file auxiliary.json in the console using CloudFormation. How can I do this?

https://stackoverflow.com/questions/67342307/how-to-add-a-dependency-file-in-aws-lambda-console-with-cloudformation-package May 01, 2021 at 10:05AM

没有评论:

发表评论