0

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.

2
  • You can package your minimal Lambda code with dependencies into a ZIP file and upload that using the awscli. Or use automation, at least CloudFormation, which is preferable. You say that you don't need API Gateway. If that's true (i.e. you know how the Lambda function will be invoked and it's not via API Gateway) then that sounds OK. You may also need to deploy IAM policies/roles etc. Commented Aug 22, 2022 at 14:35
  • On the package size with SAM, you can list the contents of the deployed ZIP file. What is in there other than your app code? Commented Aug 22, 2022 at 14:39

2 Answers 2

3

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).

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @matvey, but I don't want to use cloudformation.
2

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

4 Comments

Thanks @Utku, can you please tell me, the first option you told me about zip file, I just want to know how I will test this on local?
in local env: you can simply test with print the function(assume it is python) and see the output or run the function from terminal. but no worries, aws gives you an option to test it after you deploy as zip file; you can test it with “helloworld” test template on lambda console.
That's perfect. Can you please share the link how I can create a lambda handler, or what is the structure of lambda function and its handler?
the best documentation is dev guide lambda . you can find the answers of all your questons. docs.aws.amazon.com/lambda/latest/dg/lambda-dg.pdf

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.