Error Deploying Lambda Function in Image Mode Using AWS CodeCommit and CodeBuild

I am trying to create a lambda function with the help of AWS CodeCommit and AWS CodeBuild. I tried this in zip mode, but it exceeds the zip threshold set by the lambda function (50MB). So now I’m trying to use the image mode. But somehow I’m not able to push the code into ECR.

Any help would be appreiciated.

My buildspec.yml:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>version: 0.2
env:
variables:
AWS_DEFAULT_REGION: "us-east-1"
AWS_ACCOUNT_ID: ""
IMAGE_REPO_NAME: "deployment"
IMAGE_TAG: "latest"
S3_BUCKET: "deployment"
phases:
install:
runtime-versions:
python: 3.11
commands:
- nohup /usr/local/bin/dockerd --host=unix:///var/run/docker.sock --host=tcp://127.0.0.1:2375 --storage-driver=overlay2 &
- timeout 15 sh -c "until docker info; do echo .; sleep 1; done"
pre_build:
commands:
- echo Logging in to Amazon ECR...
- aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com || true
- REPOSITORY_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME
build:
commands:
- echo Build started on `date`
- echo Building the Docker image...
- docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG .
- docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $REPOSITORY_URI:$IMAGE_TAG
post_build:
commands:
- echo Build completed on `date`
- echo Pushing the Docker image...
- docker push $REPOSITORY_URI:$IMAGE_TAG
- echo Writing image definitions file...
- printf '[{"name":"container-name","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json
- echo Updating Lambda function...
- sed -i 's|0123.dkr.ecr.us-east-1.amazonaws.com/agent-deployment|'$REPOSITORY_URI:$IMAGE_TAG'|' template.yaml
- pip install aws-sam-cli
- sam package --template-file template.yaml --s3-bucket $S3_BUCKET --output-template-file packaged.yaml
artifacts:
files:
- packaged.yaml
- imagedefinitions.json
</code>
<code>version: 0.2 env: variables: AWS_DEFAULT_REGION: "us-east-1" AWS_ACCOUNT_ID: "" IMAGE_REPO_NAME: "deployment" IMAGE_TAG: "latest" S3_BUCKET: "deployment" phases: install: runtime-versions: python: 3.11 commands: - nohup /usr/local/bin/dockerd --host=unix:///var/run/docker.sock --host=tcp://127.0.0.1:2375 --storage-driver=overlay2 & - timeout 15 sh -c "until docker info; do echo .; sleep 1; done" pre_build: commands: - echo Logging in to Amazon ECR... - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com || true - REPOSITORY_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME build: commands: - echo Build started on `date` - echo Building the Docker image... - docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG . - docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $REPOSITORY_URI:$IMAGE_TAG post_build: commands: - echo Build completed on `date` - echo Pushing the Docker image... - docker push $REPOSITORY_URI:$IMAGE_TAG - echo Writing image definitions file... - printf '[{"name":"container-name","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json - echo Updating Lambda function... - sed -i 's|0123.dkr.ecr.us-east-1.amazonaws.com/agent-deployment|'$REPOSITORY_URI:$IMAGE_TAG'|' template.yaml - pip install aws-sam-cli - sam package --template-file template.yaml --s3-bucket $S3_BUCKET --output-template-file packaged.yaml artifacts: files: - packaged.yaml - imagedefinitions.json </code>
version: 0.2

env:
  variables:
    AWS_DEFAULT_REGION: "us-east-1"
    AWS_ACCOUNT_ID: ""
    IMAGE_REPO_NAME: "deployment"
    IMAGE_TAG: "latest"
    S3_BUCKET: "deployment"

phases:
  install:
    runtime-versions:
      python: 3.11
    commands:
      - nohup /usr/local/bin/dockerd --host=unix:///var/run/docker.sock --host=tcp://127.0.0.1:2375 --storage-driver=overlay2 &
      - timeout 15 sh -c "until docker info; do echo .; sleep 1; done"

  pre_build:
    commands:
      - echo Logging in to Amazon ECR...
      - aws ecr get-login-password --region $AWS_DEFAULT_REGION | docker login --username AWS --password-stdin $AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com || true
      - REPOSITORY_URI=$AWS_ACCOUNT_ID.dkr.ecr.$AWS_DEFAULT_REGION.amazonaws.com/$IMAGE_REPO_NAME

  build:
    commands:
      - echo Build started on `date`
      - echo Building the Docker image...
      - docker build -t $IMAGE_REPO_NAME:$IMAGE_TAG .
      - docker tag $IMAGE_REPO_NAME:$IMAGE_TAG $REPOSITORY_URI:$IMAGE_TAG

  post_build:
    commands:
      - echo Build completed on `date`
      - echo Pushing the Docker image...
      - docker push $REPOSITORY_URI:$IMAGE_TAG
      - echo Writing image definitions file...
      - printf '[{"name":"container-name","imageUri":"%s"}]' $REPOSITORY_URI:$IMAGE_TAG > imagedefinitions.json
      - echo Updating Lambda function...
      - sed -i 's|0123.dkr.ecr.us-east-1.amazonaws.com/agent-deployment|'$REPOSITORY_URI:$IMAGE_TAG'|' template.yaml
      - pip install aws-sam-cli
      - sam package --template-file template.yaml --s3-bucket $S3_BUCKET --output-template-file packaged.yaml

artifacts:
  files:
    - packaged.yaml
    - imagedefinitions.json

My template.yml :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31
Resources:
MyLambdaFunction:
Type: AWS::Serverless::Function
Properties:
PackageType: Image
ImageUri: 0123.dkr.ecr.us-east-1.amazonaws.com/agent-deployment
MemorySize: 128
Timeout: 30
Environment:
Variables:
PARAM1: "value1"
Events:
HttpApi:
Type: HttpApi
Properties:
Path: /
Method: GET
Outputs:
LambdaFunction:
Description: "Lambda Function ARN"
Value: !GetAtt MyLambdaFunction.Arn
LambdaFunctionUrl:
Description: "Lambda Function URL"
Value: !GetAtt MyLambdaFunction.FunctionUrl
</code>
<code>AWSTemplateFormatVersion: "2010-09-09" Transform: AWS::Serverless-2016-10-31 Resources: MyLambdaFunction: Type: AWS::Serverless::Function Properties: PackageType: Image ImageUri: 0123.dkr.ecr.us-east-1.amazonaws.com/agent-deployment MemorySize: 128 Timeout: 30 Environment: Variables: PARAM1: "value1" Events: HttpApi: Type: HttpApi Properties: Path: / Method: GET Outputs: LambdaFunction: Description: "Lambda Function ARN" Value: !GetAtt MyLambdaFunction.Arn LambdaFunctionUrl: Description: "Lambda Function URL" Value: !GetAtt MyLambdaFunction.FunctionUrl </code>
AWSTemplateFormatVersion: "2010-09-09"
Transform: AWS::Serverless-2016-10-31

Resources:
  MyLambdaFunction:
    Type: AWS::Serverless::Function
    Properties:
      PackageType: Image
      ImageUri: 0123.dkr.ecr.us-east-1.amazonaws.com/agent-deployment
      MemorySize: 128
      Timeout: 30
      Environment:
        Variables:
          PARAM1: "value1"
      Events:
        HttpApi:
          Type: HttpApi
          Properties:
            Path: /
            Method: GET

Outputs:
  LambdaFunction:
    Description: "Lambda Function ARN"
    Value: !GetAtt MyLambdaFunction.Arn
  LambdaFunctionUrl:
    Description: "Lambda Function URL"
    Value: !GetAtt MyLambdaFunction.FunctionUrl

Logs :

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật