# Deploy Node.js Lambda functions with container images There are three ways to build a container image for a Node.js Lambda function: + [Using an AWS base image for Node.js](#nodejs-image-instructions) The [AWS base images](images-create.md#runtimes-images-lp) are preloaded with a language runtime, a runtime interface client to manage the interaction between Lambda and your function code, and a runtime interface emulator for local testing. + [Using an AWS OS-only base image](images-create.md#runtimes-images-provided) [AWS OS-only base images](https://gallery.ecr.aws/lambda/provided) contain an Amazon Linux distribution and the [runtime interface emulator](https://github.com/aws/aws-lambda-runtime-interface-emulator/). These images are commonly used to create container images for compiled languages, such as [Go](go-image.md#go-image-provided) and [Rust](lambda-rust.md), and for a language or language version that Lambda doesn't provide a base image for, such as Node.js 19. You can also use OS-only base images to implement a [custom runtime](runtimes-custom.md). To make the image compatible with Lambda, you must include the [runtime interface client for Node.js](#nodejs-image-clients) in the image. + [Using a non-AWS base image](#nodejs-image-clients) You can use an alternative base image from another container registry, such as Alpine Linux or Debian. You can also use a custom image created by your organization. To make the image compatible with Lambda, you must include the [runtime interface client for Node.js](#nodejs-image-clients) in the image. **Tip** To reduce the time it takes for Lambda container functions to become active, see [Use multi-stage builds](https://docs.docker.com/build/building/multi-stage/) in the Docker documentation. To build efficient container images, follow the [Best practices for writing Dockerfiles](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/). This page explains how to build, test, and deploy container images for Lambda. **Topics** + [AWS base images for Node.js](#nodejs-image-base) + [Using an AWS base image for Node.js](#nodejs-image-instructions) + [Using an alternative base image with the runtime interface client](#nodejs-image-clients) ## AWS base images for Node.js AWS provides the following base images for Node.js: | Tags | Runtime | Operating system | Dockerfile | Deprecation | | --- | --- | --- | --- | --- | | 24 | Node.js 24 | Amazon Linux 2023 | [Dockerfile for Node.js 24 on GitHub](https://github.com/aws/aws-lambda-base-images/blob/nodejs24.x/Dockerfile.nodejs24.x) | Apr 30, 2028 | | 22 | Node.js 22 | Amazon Linux 2023 | [Dockerfile for Node.js 22 on GitHub](https://github.com/aws/aws-lambda-base-images/blob/nodejs22.x/Dockerfile.nodejs22.x) | Apr 30, 2027 | Amazon ECR repository: [gallery.ecr.aws/lambda/nodejs](https://gallery.ecr.aws/lambda/nodejs) The Node.js 20 and later base images are based on the [Amazon Linux 2023 minimal container image](https://docs.aws.amazon.com/linux/al2023/ug/minimal-container.html). 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 as `glibc`. AL2023-based images use `microdnf` (symlinked as `dnf`) as the package manager instead of `yum`, which is the default package manager in Amazon Linux 2. `microdnf` is a standalone implementation of `dnf`. For a list of packages that are included in AL2023-based images, refer to the **Minimal Container** columns in [Comparing packages installed on Amazon Linux 2023 Container Images](https://docs.aws.amazon.com/linux/al2023/ug/al2023-container-image-types.html). For more information about the differences between AL2023 and Amazon Linux 2, see [Introducing the Amazon Linux 2023 runtime for AWS Lambda](https://aws.amazon.com/blogs/compute/introducing-the-amazon-linux-2023-runtime-for-aws-lambda/) on the AWS Compute Blog. **Note** To run AL2023-based images locally, including with AWS Serverless Application Model (AWS SAM), you must use Docker version 20.10.10 or later. ## Using an AWS base image for Node.js ### Prerequisites To complete the steps in this section, you must have the following: + [AWS CLI version 2](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) + [Docker](https://docs.docker.com/get-docker) (minimum version 25.0.0) + The Docker [buildx plugin](https://github.com/docker/buildx/blob/master/README.md). + Node.js ### Creating an image from a base image **To create a container image from an AWS base image for Node.js** 1. Create a directory for the project, and then switch to that directory. ``` mkdir example cd example ``` 1. Create a new Node.js project with `npm`. To accept the default options provided in the interactive experience, press `Enter`. ``` npm init ``` 1. Create a new file called `index.js`. You can add the following sample function code to the file for testing, or use your own. **Example CommonJS handler** ``` exports.handler = async (event) => { const response = { statusCode: 200, body: JSON.stringify('Hello from Lambda!'), }; return response; }; ``` 1. If your function depends on libraries other than the AWS SDK for JavaScript, use [npm](https://www.npmjs.com/) to add them to your package. 1. Create a new Dockerfile with the following configuration: + Set the `FROM` property to the [URI of the base image](https://gallery.ecr.aws/lambda/nodejs). + Use the COPY command to copy the function code and runtime dependencies to `{LAMBDA_TASK_ROOT}`, a [Lambda-defined environment variable](configuration-envvars.md#configuration-envvars-runtime). + Set the `CMD` argument to the Lambda function handler. Note that the example Dockerfile does not include a [USER instruction](https://docs.docker.com/reference/dockerfile/#user). When you deploy a container image to Lambda, Lambda automatically defines a default Linux user with least-privileged permissions. This is different from standard Docker behavior which defaults to the `root` user when no `USER` instruction is provided. **Example Dockerfile** ``` FROM {{public.ecr.aws/lambda/nodejs:22}} # Copy function code COPY {{index.js}} ${LAMBDA_TASK_ROOT} # Set the CMD to your handler (could also be done as a parameter override outside of the Dockerfile) CMD [ "{{index.handler}}" ] ``` 1. Build the Docker image with the [docker build](https://docs.docker.com/engine/reference/commandline/build/) command. The following example names the image `docker-image` and gives it the `test` [tag](https://docs.docker.com/engine/reference/commandline/build/#tag). To make your image compatible with Lambda, you must use the `--provenance=false` option. ``` docker buildx build --platform linux/amd64 --provenance=false -t {{docker-image}}:{{test}} . ``` **Note** The command specifies the `--platform linux/amd64` option to ensure that your container is compatible with the Lambda execution environment regardless of the architecture of your build machine. If you intend to create a Lambda function using the ARM64 instruction set architecture, be sure to change the command to use the `--platform linux/arm64` option instead. ### (Optional) Test the image locally 1. Start the Docker image with the **docker run** command. In this example, `docker-image` is the image name and `test` is the tag. ``` docker run --platform linux/amd64 -p 9000:8080 {{docker-image}}:{{test}} ``` This command runs the image as a container and creates a local endpoint at `localhost:9000/2015-03-31/functions/function/invocations`. **Note** If you built the Docker image for the ARM64 instruction set architecture, be sure to use the `--platform linux/{{arm64}}` option instead of `--platform linux/{{amd64}}`. 1. From a new terminal window, post an event to the local endpoint. ------ #### [ Linux/macOS ] In Linux and macOS, run the following `curl` command: ``` curl "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}' ``` This command invokes the function with an empty event and returns a response. If you're using your own function code rather than the sample function code, you might want to invoke the function with a JSON payload. Example: ``` curl "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{{{"payload":"hello world!"}}}' ``` ------ #### [ PowerShell ] In PowerShell, run the following `Invoke-WebRequest` command: ``` Invoke-WebRequest -Uri "http://localhost:9000/2015-03-31/functions/function/invocations" -Method Post -Body '{}' -ContentType "application/json" ``` This command invokes the function with an empty event and returns a response. If you're using your own function code rather than the sample function code, you might want to invoke the function with a JSON payload. Example: ``` Invoke-WebRequest -Uri "http://localhost:9000/2015-03-31/functions/function/invocations" -Method Post -Body '{{{"payload":"hello world!"}}}' -ContentType "application/json" ``` ------ 1. Get the container ID. ``` docker ps ``` 1. Use the [docker kill](https://docs.docker.com/engine/reference/commandline/kill/) command to stop the container. In this command, replace `3766c4ab331c` with the container ID from the previous step. ``` docker kill {{3766c4ab331c}} ``` ### Deploying the image **To upload the image to Amazon ECR and create the Lambda function** 1. Run the [get-login-password](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ecr/get-login-password.html) command to authenticate the Docker CLI to your Amazon ECR registry. + Set the `--region` value to the AWS Region where you want to create the Amazon ECR repository. + Replace `111122223333` with your AWS account ID. ``` aws ecr get-login-password --region {{us-east-1}} | docker login --username AWS --password-stdin {{111122223333}}.dkr.ecr.{{us-east-1}}.amazonaws.com ``` 1. Create a repository in Amazon ECR using the [create-repository](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ecr/create-repository.html) command. ``` aws ecr create-repository --repository-name {{hello-world}} --region {{us-east-1}} --image-scanning-configuration scanOnPush=true --image-tag-mutability MUTABLE ``` **Note** The Amazon ECR repository must be in the same AWS Region as the Lambda function. If successful, you see a response like this: ``` { "repository": { "repositoryArn": "arn:aws:ecr:us-east-1:111122223333:repository/hello-world", "registryId": "111122223333", "repositoryName": "hello-world", "repositoryUri": "111122223333.dkr.ecr.us-east-1.amazonaws.com/hello-world", "createdAt": "2023-03-09T10:39:01+00:00", "imageTagMutability": "MUTABLE", "imageScanningConfiguration": { "scanOnPush": true }, "encryptionConfiguration": { "encryptionType": "AES256" } } } ``` 1. Copy the `repositoryUri` from the output in the previous step. 1. Run the [docker tag](https://docs.docker.com/engine/reference/commandline/tag/) command to tag your local image into your Amazon ECR repository as the latest version. In this command: + `docker-image:test` is the name and [tag](https://docs.docker.com/engine/reference/commandline/build/#tag) of your Docker image. This is the image name and tag that you specified in the `docker build` command. + Replace `` with the `repositoryUri` that you copied. Make sure to include `:latest` at the end of the URI. ``` docker tag docker-image:test {{}}:latest ``` Example: ``` docker tag {{docker-image}}:{{test}} {{111122223333}}.dkr.ecr.{{us-east-1}}.amazonaws.com/{{hello-world}}:latest ``` 1. Run the [docker push](https://docs.docker.com/engine/reference/commandline/push/) command to deploy your local image to the Amazon ECR repository. Make sure to include `:latest` at the end of the repository URI. ``` docker push {{111122223333}}.dkr.ecr.{{us-east-1}}.amazonaws.com/{{hello-world}}:latest ``` 1. [Create an execution role](lambda-intro-execution-role.md#permissions-executionrole-api) for the function, if you don't already have one. You need the Amazon Resource Name (ARN) of the role in the next step. 1. Create the Lambda function. For `ImageUri`, specify the repository URI from earlier. Make sure to include `:latest` at the end of the URI. ``` aws lambda create-function \ --function-name {{hello-world}} \ --package-type Image \ --code ImageUri={{111122223333}}.dkr.ecr.{{us-east-1}}.amazonaws.com/{{hello-world}}:latest \ --role {{arn:aws:iam::111122223333:role/lambda-ex}} ``` **Note** You can create a function using an image in a different AWS account, as long as the image is in the same Region as the Lambda function. For more information, see [Amazon ECR cross-account permissions](images-create.md#configuration-images-xaccount-permissions). 1. Invoke the function. ``` aws lambda invoke --function-name {{hello-world}} response.json ``` You should see a response like this: ``` { "ExecutedVersion": "$LATEST", "StatusCode": 200 } ``` 1. To see the output of the function, check the `response.json` file. To update the function code, you must build the image again, upload the new image to the Amazon ECR repository, and then use the [update-function-code](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/update-function-code.html) command to deploy the image to the Lambda function. Lambda resolves the image tag to a specific image digest. This means that if you point the image tag that was used to deploy the function to a new image in Amazon ECR, Lambda doesn't automatically update the function to use the new image. To deploy the new image to the same Lambda function, you must use the [update-function-code](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/update-function-code.html) command, even if the image tag in Amazon ECR remains the same. In the following example, the `--publish` option creates a new version of the function using the updated container image. ``` aws lambda update-function-code \ --function-name {{hello-world}} \ --image-uri {{111122223333.dkr.ecr.us-east-1.amazonaws.com/hello-world:latest}} \ --publish ``` ## Using an alternative base image with the runtime interface client If you use an [OS-only base image](images-create.md#runtimes-images-provided) or an alternative base image, you must include the runtime interface client in your image. The runtime interface client extends the [Runtime API](runtimes-api.md), which manages the interaction between Lambda and your function code. Install the [Node.js runtime interface client](https://www.npmjs.com/package/aws-lambda-ric) using the npm package manager: ``` npm install aws-lambda-ric ``` You can also download the [Node.js runtime interface client](https://github.com/aws/aws-lambda-nodejs-runtime-interface-client) from GitHub. The following example demonstrates how to build a container image for Node.js using a non-AWS base image. The example Dockerfile uses a `bookworm` base image. The Dockerfile includes the runtime interface client. ### Prerequisites To complete the steps in this section, you must have the following: + [AWS CLI version 2](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html) + [Docker](https://docs.docker.com/get-docker) (minimum version 25.0.0) + The Docker [buildx plugin](https://github.com/docker/buildx/blob/master/README.md). + Node.js ### Creating an image from an alternative base image **To create a container image from a non-AWS base image** 1. Create a directory for the project, and then switch to that directory. ``` mkdir example cd example ``` 1. Create a new Node.js project with `npm`. To accept the default options provided in the interactive experience, press `Enter`. ``` npm init ``` 1. Create a new file called `index.js`. You can add the following sample function code to the file for testing, or use your own. **Example CommonJS handler** ``` exports.handler = async (event) => { const response = { statusCode: 200, body: JSON.stringify('Hello from Lambda!'), }; return response; }; ``` 1. Create a new Dockerfile. The following Dockerfile uses a `bookworm` base image instead of an [AWS base image](images-create.md#runtimes-images-lp). The Dockerfile includes the [runtime interface client](https://www.npmjs.com/package/aws-lambda-ric), which makes the image compatible with Lambda. The Dockerfile uses a [multi-stage build](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#use-multi-stage-builds). The first stage creates a build image, which is a standard Node.js environment where the function's dependencies are installed. The second stage creates a slimmer image which includes the function code and its dependencies. This reduces the final image size. + Set the `FROM` property to the base image identifier. + Use the `COPY` command to copy the function code and runtime dependencies. + Set the `ENTRYPOINT` to the module that you want the Docker container to run when it starts. In this case, the module is the runtime interface client. + Set the `CMD` argument to the Lambda function handler. Note that the example Dockerfile does not include a [USER instruction](https://docs.docker.com/reference/dockerfile/#user). When you deploy a container image to Lambda, Lambda automatically defines a default Linux user with least-privileged permissions. This is different from standard Docker behavior which defaults to the `root` user when no `USER` instruction is provided. **Example Dockerfile** ``` # Define custom function directory ARG FUNCTION_DIR="/function" FROM {{node:20-bookworm}} as build-image # Include global arg in this stage of the build ARG FUNCTION_DIR # Install build dependencies RUN apt-get update && \ apt-get install -y \ g++ \ make \ cmake \ unzip \ libcurl4-openssl-dev # Copy function code RUN mkdir -p ${FUNCTION_DIR} COPY . ${FUNCTION_DIR} WORKDIR ${FUNCTION_DIR} # Install Node.js dependencies RUN npm install # Install the runtime interface client RUN npm install aws-lambda-ric # Grab a fresh slim copy of the image to reduce the final size FROM {{node:20-bookworm-slim}} # Required for Node runtimes which use npm@8.6.0+ because # by default npm writes logs under /home/.npm and Lambda fs is read-only ENV NPM_CONFIG_CACHE=/tmp/.npm # Include global arg in this stage of the build ARG FUNCTION_DIR # Set working directory to function root directory WORKDIR ${FUNCTION_DIR} # Copy in the built dependencies COPY --from=build-image ${FUNCTION_DIR} ${FUNCTION_DIR} # Set runtime interface client as default command for the container runtime ENTRYPOINT ["{{/usr/local/bin/npx", "aws-lambda-ric"}}] # Pass the name of the function handler as an argument to the runtime CMD ["{{index.handler}}"] ``` 1. Build the Docker image with the [docker build](https://docs.docker.com/engine/reference/commandline/build/) command. The following example names the image `docker-image` and gives it the `test` [tag](https://docs.docker.com/engine/reference/commandline/build/#tag). To make your image compatible with Lambda, you must use the `--provenance=false` option. ``` docker buildx build --platform linux/amd64 --provenance=false -t {{docker-image}}:{{test}} . ``` **Note** The command specifies the `--platform linux/amd64` option to ensure that your container is compatible with the Lambda execution environment regardless of the architecture of your build machine. If you intend to create a Lambda function using the ARM64 instruction set architecture, be sure to change the command to use the `--platform linux/arm64` option instead. ### (Optional) Test the image locally Use the [runtime interface emulator](https://github.com/aws/aws-lambda-runtime-interface-emulator/) to locally test the image. You can [build the emulator into your image](https://github.com/aws/aws-lambda-runtime-interface-emulator/?tab=readme-ov-file#build-rie-into-your-base-image) or use the following procedure to install it on your local machine. **To install and run the runtime interface emulator on your local machine** 1. From your project directory, run the following command to download the runtime interface emulator (x86-64 architecture) from GitHub and install it on your local machine. ------ #### [ Linux/macOS ] ``` mkdir -p ~/.aws-lambda-rie && \ curl -Lo ~/.aws-lambda-rie/aws-lambda-rie https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie && \ chmod +x ~/.aws-lambda-rie/aws-lambda-rie ``` To install the arm64 emulator, replace the GitHub repository URL in the previous command with the following: ``` https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie-arm64 ``` ------ #### [ PowerShell ] ``` $dirPath = "$HOME\.aws-lambda-rie" if (-not (Test-Path $dirPath)) { New-Item -Path $dirPath -ItemType Directory } $downloadLink = "https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie" $destinationPath = "$HOME\.aws-lambda-rie\aws-lambda-rie" Invoke-WebRequest -Uri $downloadLink -OutFile $destinationPath ``` To install the arm64 emulator, replace the `$downloadLink` with the following: ``` https://github.com/aws/aws-lambda-runtime-interface-emulator/releases/latest/download/aws-lambda-rie-arm64 ``` ------ 1. Start the Docker image with the **docker run** command. Note the following: + `docker-image` is the image name and `test` is the tag. + `/usr/local/bin/npx aws-lambda-ric index.handler` is the `ENTRYPOINT` followed by the `CMD` from your Dockerfile. ------ #### [ Linux/macOS ] ``` docker run --platform linux/amd64 -d -v ~/.aws-lambda-rie:/aws-lambda -p 9000:8080 \ --entrypoint /aws-lambda/aws-lambda-rie \ {{docker-image:test}} \ {{/usr/local/bin/npx aws-lambda-ric index.handler}} ``` ------ #### [ PowerShell ] ``` docker run --platform linux/amd64 -d -v "$HOME\.aws-lambda-rie:/aws-lambda" -p 9000:8080 ` --entrypoint /aws-lambda/aws-lambda-rie ` {{docker-image:test}} ` {{/usr/local/bin/npx aws-lambda-ric index.handler}} ``` ------ This command runs the image as a container and creates a local endpoint at `localhost:9000/2015-03-31/functions/function/invocations`. **Note** If you built the Docker image for the ARM64 instruction set architecture, be sure to use the `--platform linux/{{arm64}}` option instead of `--platform linux/{{amd64}}`. 1. Post an event to the local endpoint. ------ #### [ Linux/macOS ] In Linux and macOS, run the following `curl` command: ``` curl "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{}' ``` This command invokes the function with an empty event and returns a response. If you're using your own function code rather than the sample function code, you might want to invoke the function with a JSON payload. Example: ``` curl "http://localhost:9000/2015-03-31/functions/function/invocations" -d '{{{"payload":"hello world!"}}}' ``` ------ #### [ PowerShell ] In PowerShell, run the following `Invoke-WebRequest` command: ``` Invoke-WebRequest -Uri "http://localhost:9000/2015-03-31/functions/function/invocations" -Method Post -Body '{}' -ContentType "application/json" ``` This command invokes the function with an empty event and returns a response. If you're using your own function code rather than the sample function code, you might want to invoke the function with a JSON payload. Example: ``` Invoke-WebRequest -Uri "http://localhost:9000/2015-03-31/functions/function/invocations" -Method Post -Body '{{{"payload":"hello world!"}}}' -ContentType "application/json" ``` ------ 1. Get the container ID. ``` docker ps ``` 1. Use the [docker kill](https://docs.docker.com/engine/reference/commandline/kill/) command to stop the container. In this command, replace `3766c4ab331c` with the container ID from the previous step. ``` docker kill {{3766c4ab331c}} ``` ### Deploying the image **To upload the image to Amazon ECR and create the Lambda function** 1. Run the [get-login-password](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ecr/get-login-password.html) command to authenticate the Docker CLI to your Amazon ECR registry. + Set the `--region` value to the AWS Region where you want to create the Amazon ECR repository. + Replace `111122223333` with your AWS account ID. ``` aws ecr get-login-password --region {{us-east-1}} | docker login --username AWS --password-stdin {{111122223333}}.dkr.ecr.{{us-east-1}}.amazonaws.com ``` 1. Create a repository in Amazon ECR using the [create-repository](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/ecr/create-repository.html) command. ``` aws ecr create-repository --repository-name {{hello-world}} --region {{us-east-1}} --image-scanning-configuration scanOnPush=true --image-tag-mutability MUTABLE ``` **Note** The Amazon ECR repository must be in the same AWS Region as the Lambda function. If successful, you see a response like this: ``` { "repository": { "repositoryArn": "arn:aws:ecr:us-east-1:111122223333:repository/hello-world", "registryId": "111122223333", "repositoryName": "hello-world", "repositoryUri": "111122223333.dkr.ecr.us-east-1.amazonaws.com/hello-world", "createdAt": "2023-03-09T10:39:01+00:00", "imageTagMutability": "MUTABLE", "imageScanningConfiguration": { "scanOnPush": true }, "encryptionConfiguration": { "encryptionType": "AES256" } } } ``` 1. Copy the `repositoryUri` from the output in the previous step. 1. Run the [docker tag](https://docs.docker.com/engine/reference/commandline/tag/) command to tag your local image into your Amazon ECR repository as the latest version. In this command: + `docker-image:test` is the name and [tag](https://docs.docker.com/engine/reference/commandline/build/#tag) of your Docker image. This is the image name and tag that you specified in the `docker build` command. + Replace `` with the `repositoryUri` that you copied. Make sure to include `:latest` at the end of the URI. ``` docker tag docker-image:test {{}}:latest ``` Example: ``` docker tag {{docker-image}}:{{test}} {{111122223333}}.dkr.ecr.{{us-east-1}}.amazonaws.com/{{hello-world}}:latest ``` 1. Run the [docker push](https://docs.docker.com/engine/reference/commandline/push/) command to deploy your local image to the Amazon ECR repository. Make sure to include `:latest` at the end of the repository URI. ``` docker push {{111122223333}}.dkr.ecr.{{us-east-1}}.amazonaws.com/{{hello-world}}:latest ``` 1. [Create an execution role](lambda-intro-execution-role.md#permissions-executionrole-api) for the function, if you don't already have one. You need the Amazon Resource Name (ARN) of the role in the next step. 1. Create the Lambda function. For `ImageUri`, specify the repository URI from earlier. Make sure to include `:latest` at the end of the URI. ``` aws lambda create-function \ --function-name {{hello-world}} \ --package-type Image \ --code ImageUri={{111122223333}}.dkr.ecr.{{us-east-1}}.amazonaws.com/{{hello-world}}:latest \ --role {{arn:aws:iam::111122223333:role/lambda-ex}} ``` **Note** You can create a function using an image in a different AWS account, as long as the image is in the same Region as the Lambda function. For more information, see [Amazon ECR cross-account permissions](images-create.md#configuration-images-xaccount-permissions). 1. Invoke the function. ``` aws lambda invoke --function-name {{hello-world}} response.json ``` You should see a response like this: ``` { "ExecutedVersion": "$LATEST", "StatusCode": 200 } ``` 1. To see the output of the function, check the `response.json` file. To update the function code, you must build the image again, upload the new image to the Amazon ECR repository, and then use the [update-function-code](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/update-function-code.html) command to deploy the image to the Lambda function. Lambda resolves the image tag to a specific image digest. This means that if you point the image tag that was used to deploy the function to a new image in Amazon ECR, Lambda doesn't automatically update the function to use the new image. To deploy the new image to the same Lambda function, you must use the [update-function-code](https://awscli.amazonaws.com/v2/documentation/api/latest/reference/lambda/update-function-code.html) command, even if the image tag in Amazon ECR remains the same. In the following example, the `--publish` option creates a new version of the function using the updated container image. ``` aws lambda update-function-code \ --function-name {{hello-world}} \ --image-uri {{111122223333.dkr.ecr.us-east-1.amazonaws.com/hello-world:latest}} \ --publish ```

AltStyle によって変換されたページ (->オリジナル) /