Creating Lambda functions defined as .zip file archives - AWS Lambda

Creating Lambda functions defined as .zip file archives

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.

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.

Note

You cannot convert an existing container image function to use a .zip file archive. You must create a new function.

Creating a function (console)

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.

To create the function

  1. Open the Functions page on the Lambda console.

  2. Choose Create function.

  3. Choose Author from scratch or Use a blueprint to create your function.

  4. Under Basic information, do the following:

    1. For Function name, enter the function name.

    2. For Runtime, choose the language version to use for your function.

  5. (Optional) Under Permissions, expand Change default execution role. You can create a new Execution role or use an existing role.

  6. (Optional) Expand Advanced settings. You can choose a Code signing configuration for the function. You can also configure an (Amazon VPC) for the function to access.

  7. Choose Create function.

Lambda creates the new function. You can now use the console to add the function code and configure other function parameters and features.

Using the console code editor

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, choose Save. Then, to run your code, choose Test.

Note

The Lambda console uses AWS Cloud9 to provide an integrated development environment in the browser. You can also use AWS Cloud9 to develop Lambda functions in your own environment. For more information, see Working with Lambda Functions in the AWS Cloud9 user guide.

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 SDE) you need to create a deployment package to upload your code to the Lambda function.

Updating function code (console)

For scripting languages (Node.js, Python, and Ruby), you can edit your function code in the embedded code editor. 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. You can upload the zip archive from your local machine. If the .zip archive is larger than 50 MB, upload the file to the function from an Amazon S3 bucket.

To upload function code as a .zip archive

  1. Open the Functions page on the Lambda console.

  2. Choose the function to update and choose the Code tab.

  3. Under Code source, choose Upload from.

  4. Choose .zip file and then choose Upload.

    1. In the file chooser, select the new image version and choose Open, then choose Save.

  5. (Alternative to step 4) Choose Amazon S3 location.

    1. In the text box, enter the S3 link URL of the .zip file archive, then choose Save.

Configuring runtime settings (console)

When you create a function that uses a .zip file deployment package, you must specify the runtime to use and the name of the function handler.

To update the runtime settings

  1. Open the Functions page on the Lambda console.

  2. Choose the function to update and choose the Code tab.

  3. Under Runtime settings, choose Edit.

    1. For Runtime, select the runtime version.

    2. For Handler, specify file name and handler for your function.

  4. Choose Save.

Using the Lambda API

To create and configure a function that uses a .zip file archive, use the following API operations:

AWS CloudFormation

You can use AWS CloudFormation to create a Lambda function that uses a .zip file archive. In your AWS CloudFormation template, the AWS::Lambda::Function resource specifies the Lambda function. For descriptions of the properties in the AWS::Lambda::Function resource, see AWS::Lambda::Function in the AWS CloudFormation User Guide.

In the AWS::Lambda::Function resource, set the following properties to create a function defined as a .zip file archive:

  • AWS::Lambda::Function

    • PackageType – Set to Zip.

    • Code – Enter the Amazon S3 bucket name and .zip file name in the S3Bucket and S3Keyfields. For Node.js or Python, you can provide inline source code of your Lambda function.

    • Runtime – Set the runtime value.