Home > Blockchain >  Can we set up AWS Lambda function locally without using AWS Sam?
Can we set up AWS Lambda function locally without using AWS Sam?

Time:08-24

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:

  1. Create Lambda function on local machine for development
  2. I don't want to shift my Lambda function manually from local environment to AWS Console.
  3. 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.

CodePudding user response:

Use local devtools which simplify cloud infrastructure local development and automate the process of deployment.

Check for example Altostra local devtools:

  1. VS Code extension to build AWS infrastructure in visual way, including configuration of each AWS resource (extension is available on official VS Code marketplace)
  2. CLI (available on official npm marketplace) - automatically package all your code and cloud infrastructure and push it to your AWS account. After push you can also deploy your project directly from your local dev environment to AWS - Altostra automatically generates CloudFormation from your visual design and deploy the stack to your AWS account. All permissions are generated automatically as well.

Notice, you need to open an account on Altostra to be able to do all described in #2 (account is free).

CodePudding user response:

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

  • Related