When you create a Lambda function, you package your function code into a deployment package. Lambda supports two types of deployment packages: container images and .zip file archives. The workflow to create a function depends on the deployment package type. To configure a function defined as a container image, seeCreate a Lambda function using a container image.
You can use the Lambda console and the Lambda API to create a function defined with a .zip file archive. You can also upload an updated .zip file to change the function code.
You cannot change thedeployment package type (.zip or container image) for an existing function. For example, you cannot convert a container image function to use a .zip file archive. You must create a new function.
When you create a function defined with a .zip file archive, you choose a code template, the language version, and the execution role for the function. You add your function code after Lambda creates the function.
Open theFunctions page of the Lambda console.
ChooseCreate function.
ChooseAuthor from scratch orUse a blueprint to create your function.
UnderBasic information, do the following:
ForFunction name, enter the function name. Function names are limited to 64 characters in length.
ForRuntime, choose the language version to use for your function.
(Optional) ForArchitecture, choose the instruction set architecture to use for your function. The default architecture is x86_64. When you build the deployment package for your function, make sure that it is compatible with thisinstruction set architecture.
(Optional) UnderPermissions, expandChange default execution role. You can create a newExecution role or use an existing role.
(Optional) ExpandAdvanced settings. You can choose aCode signing configuration for the function. You can also configure an (Amazon VPC) for the function to access.
ChooseCreate function.
Lambda creates the new function. You can now use the console to add the function code and configure other function parameters and features. For code deployment instructions, see the handler page for the runtime your function uses.
Build and deploy C# Lambda functions with .zip file archives
The console creates a Lambda function with a single source file. For scripting languages, you can edit this file and add more files using the built-in code editor. To save your changes, chooseSave. Then, to run your code, chooseTest.
When you save your function code, the Lambda console creates a .zip file archive deployment package. When you develop your function code outside of the console (using an IDE) you need tocreate a deployment package to upload your code to the Lambda function.
For scripting languages (Node.js, Python, and Ruby), you can edit your function code in the embedded code editor. If the code is larger than 3MB, or if you need to add libraries, or for languages that the editor doesn't support (Java, Go, C#), you must upload your function code as a .zip archive. If the .zip file archive is smaller than 50 MB, you can upload the .zip file archive from your local machine. If the file is larger than 50 MB, upload the file to the function from an Amazon S3 bucket.
Open theFunctions page of the Lambda console.
Choose the function to update and choose theCode tab.
UnderCode source, chooseUpload from.
Choose.zip file, and then chooseUpload.
In the file chooser, select the new image version, chooseOpen, and then chooseSave.
(Alternative to step 4) ChooseAmazon S3 location.
In the text box, enter the S3 link URL of the .zip file archive, then chooseSave.
If you update the function configuration to use a new runtime, you may need to update the function code to be compatible with the new runtime. If you update the function configuration to use a different runtime, youmust provide new function code that is compatible with the runtime and architecture. For instructions on how to create a deployment package for the function code, see the handler page for the runtime that the function uses.
The Node.js 20, Python 3.12, Java 21, .NET 8, Ruby 3.3, and later base images are based on the Amazon Linux 2023 minimal container image. Earlier base images use Amazon Linux 2. AL2023 provides several advantages over Amazon Linux 2, including a smaller deployment footprint and updated versions of libraries such asglibc
. For more information, seeIntroducing the Amazon Linux 2023 runtime for AWS Lambda on the AWS Compute Blog.
Open theFunctions page of the Lambda console.
Choose the function to update and choose theCode tab.
Scroll down to theRuntime settings section, which is under the code editor.
ChooseEdit.
ForRuntime, select the runtime identifier.
ForHandler, specify file name and handler for your function.
ForArchitecture, choose the instruction set architecture to use for your function.
ChooseSave.
Before you can change the instruction set architecture, you need to ensure that your function's code is compatible with the target architecture.
If you use Node.js, Python, or Ruby and you edit your function code in the embedded editor, the existing code may run without modification.
However, if you provide your function code using a .zip file archive deployment package, you must prepare a new .zip file archive that is compiled and built correctly for the target runtime and instruction-set architecture. For instructions, see the handler page for your function runtime.
Open theFunctions page of the Lambda console.
Choose the function to update and choose theCode tab.
UnderRuntime settings, chooseEdit.
ForArchitecture, choose the instruction set architecture to use for your function.
ChooseSave.
To create and configure a function that uses a .zip file archive, use the following API operations:
You can download the current unpublished ($LATEST
) version of your function code .zip via the Lambda console. To do this, first ensure that you have the following IAM permissions:
iam:GetPolicy
iam:GetPolicyVersion
iam:GetRole
iam:GetRolePolicy
iam:ListAttachedRolePolicies
iam:ListRolePolicies
iam:ListRoles
Open theFunctions page of the Lambda console.
Choose the function you want to download the function code .zip for.
In theFunction overview, choose theDownload button, then chooseDownload function code .zip.
Alternatively, chooseDownload AWS SAM file to generate and download a SAM template based on your function's configuration. You can also chooseDownload both to download both the .zip and the SAM template.
You can use AWS CloudFormation to create a Lambda function that uses a .zip file archive. In your AWS CloudFormation template, theAWS::Lambda::Function
resource specifies the Lambda function. For descriptions of the properties in theAWS::Lambda::Function
resource, seeAWS::Lambda::Function in theAWS CloudFormation User Guide.
In theAWS::Lambda::Function
resource, set the following properties to create a function defined as a .zip file archive:
AWS::Lambda::Function
PackageType – Set toZip
.
Code – Enter the Amazon S3 bucket name and .zip file name in theS3Bucket
andS3Key
fields. For Node.js or Python, you can provide inline source code of your Lambda function.
Runtime – Set the runtime value.
Architecture – Set the architecture value toarm64
to use the AWS Graviton2 processor. By default, the architecture value isx86_64
.