I have set up a lambda function using AWS Sam CLI that I am using for local development. After development, I have deployed this function to AWS console for production from my IDE (visual studio code). After deployment, when I see It has created several other resources such as cloudformation, Api Gateway, and a few others.
What’s problem?
I am seeking a way through which I can deploy only my Lambda code that doesn’t create other resources like Api gateway, etc. Is there any way that allow me to only create lambda function on local environment and then I want to push my code to AWS console.
Moreover, when I use AWS Sam the size of my Lambda code also increased incredibly. When I created the same Lambda manually on AWS Console it consumes only a few kbs but when I created Lambda using AWS Sam it’s size ramped up to 25MB.
If someone know a better way to do this please elaborate.
You can see my concerns the following:
- Create Lambda function on local machine for development
- I don’t want to shift my Lambda function manually from local environment to AWS Console.
- Also assign the Lambda function with specific permissions
What are the best practices for this? If someone is still confuse please ask anything in the comment section.
2
Answers
You can upload your application to aws lambda in 3 way :
1- Create a zip file and upload via console (project files can not exceed 250mb)
2- Upload your files to s3 and reference it (doable)
3- Create docker images and upload it (the easiest way)
The best way is to upload as container images because you can upload files/dependencies up to 10gb inside the docker image.
After you create your docker images, you can test it locally too. Please check :
https://docs.aws.amazon.com/lambda/latest/dg/images-test.html
Use local devtools which simplify cloud infrastructure local development and automate the process of deployment.
Check for example Altostra local devtools:
Notice, you need to open an account on Altostra to be able to do all described in #2 (account is free).