AWS SAM 管道

问题描述

我正在尝试使用 Python 3.8 为标准 AWS SAM HelloWorld 模板构建管道。我使用 this template 作为管道示例。我对管道所做的唯一更改是环境/图像,我将其从 3.6.5 更改为 3.8.3,就像这样...

     CodeBuildProject:
        Type: AWS::CodeBuild::Project
        Properties:
            Name: {{cookiecutter.project_name.lower().replace(' ','-')}}
            Description: Build project for the {{cookiecutter.project_name}}
            Artifacts:
              Type: CODEPIPELINE
            Environment: 
                Type: LINUX_CONTAINER
                ComputeType: BUILD_GENERAL1_SMALL
                # Image: aws/codebuild/python:3.6.5 - *Commenting this out*
                Image: aws/codebuild/python:3.8.3 - *Using this instead*
                Environmentvariables:
                  - 
                    Name: BUILD_OUTPUT_BUCKET
                    Value: !Ref BuildArtifactsBucket
            Cache:
              Type: S3
              Location: !Sub ${BuildArtifactsBucket}/codebuild-cache
            ServiceRole: !GetAtt CodeBuildServiceRole.Arn
            Source: 
                Type: CODEPIPELINE
            Tags: 
              - 
                Key: "Stack"
                Value: !Ref AWS::StackName
              -
                Key: "Project"
                Value: {{cookiecutter.project_name}}

问题

我进行此更改是因为我的 lambda 的运行时是 python3.8。如果我将管道的图像保留为 aws/codebuild/python:3.6.5,则会出现以下错误...

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/aws_lambda_builders/workflow.py",line 58,in wrapper
    valid_path = binary_checker.validator.validate(executable_path)
  File "/usr/local/lib/python3.6/site-packages/aws_lambda_builders/workflows/python_pip/validator.py",line 45,in validate
    raise MisMatchRuntimeError(language=self.language,required_runtime=self.runtime,runtime_path=runtime_path)
aws_lambda_builders.exceptions.MisMatchRuntimeError: python executable found in your path does not match runtime. 
 Expected version: python3.8,Found version: /usr/local/bin/python.

但是,当我将管道的图像更改为 aws/codebuild/python:3.8.3 时,我在 CodeBuild 的配置阶段收到此错误...

BUILD_CONTAINER_UNABLE_TO_PULL_IMAGE: Unable to pull customer's container image. CannotPullContainerError: Error response from daemon: pull access denied for aws/codebuild/python,repository does not exist or may require 'docker login': denied: requested access to the resource is denied

当我搜索“codebuild BUILD_CONTAINER_UNABLE_TO_PULL_IMAGE”时,我发现错误来自使用自定义构建映像。

我的问题

  1. 我将管道的图像更改为 aws/codebuild/python:3.8.3 是否正确
  2. aws/codebuild/python:3.8.3 是有效图片吗?

关于 #2,我找到了 this page,虽然筛选起来有点复杂,但我相信 3.8.3 是一个有效的图像。

如果您能帮助我的管道运行,我们将不胜感激。

解决方法

这是因为它试图从具有 throttling enabled for pulling images 的 docker hub 拉取新镜像。因此,您可以做的是从 AWS Public ECR 中提取图像并在您的环境中使用相同的图像。

还有另一种方法,您可以在帐户中创建自己的 ECR 存储库,并将提到的图像推送到您自己的 ECR 并在模板中使用它。