0
votes

Is it possible to run a docker in lambda?

Error: Response: { "errorType": "Runtime.ExitError", "errorMessage": "RequestId: d7a7dc46-b4e2-439b-a16b-e4ee1de1f7c5 Error: Runtime exited with error: exit status 127" }

Request ID: "d7a7dc46-b4e2-439b-a16b-e4ee1de1f7c5"

Function logs: START RequestId: d7a7dc46-b4e2-439b-a16b-e4ee1de1f7c5 Version: $LATEST /var/task/function.sh: line 22: docker: command not found END RequestId: d7a7dc46-b4e2-439b-a16b-e4ee1de1f7c5 REPORT RequestId: d7a7dc46-b4e2-439b-a16b-e4ee1de1f7c5 Duration: 18437.78 ms Billed Duration: 18500 ms Memory Size: 128 MB Max Memory Used: 90 MB Init Duration: 32.58 ms RequestId: d7a7dc46-b4e2-439b-a16b-e4ee1de1f7c5 Error: Runtime exited with error: exit status 127 Runtime.ExitError

Code:

 function handler () {
set -e

dstRegion="${1:-}"
repoName="${2:-}"

echo "login source registry"
    $(aws ecr get-login   --no-include-email --region $ECR_SRC_REGION)
    srcImage="$ECR_SRC_REG_ID.dkr.ecr.$ECR_SRC_REGION.amazonaws.com/$repoName:ECR_REPO_TAG"

    echo "pull image"
    docker pull $srcImage
    
    targetRegions=${ECR_TARGET_REGIONS}

    IFS=","; for reg in $targetRegions; do
      check_create_repo $reg $ECR_REPO_NAME

      echo "target region $reg"
      
      targetImage="$ECR_SRC_REG_ID.dkr.ecr.$reg.amazonaws.com/$ECR_REPO_NAME:$ECR_REPO_TAG"

      echo "target Image: $targetImage"
      echo "tagging images"

      docker tag $srcImage $targetImage

      echo "login target registry in $reg"

      aws ecr get-login  --no-include-email --region $reg | bash

      echo "push image to target region $reg"
      echo "pushing $targetImage"

      docker push $targetImage
    done
}
1
No... You can not run docker container in lambda function...Chetan

1 Answers

0
votes

Sadly, you can't run docker in the lambda environment. However, even if you could the usefulness of it would be very limited as lambda can run for maximum 15 minutes.

If you want to run docker applications on AWS, there are two options which are usually used for this purpose:

The later is basically serverless equivalent of the first one, where you can just deploy your docker containers and don't worry about managing/scaling underlining infrastructure.

A recommended read is also AWS whitepapter: