我正在 AWS 代码管道中构建 Docker 映像并将其推送到 ECR。推送后,我想更新 lambda 函数以在 ECR 中使用这个较新版本的存储库。我的构建 yaml 文件如下所示:
build:
commands:
- echo Entered the post_build phase...
- echo Build completed on `date`
- docker build -t $imageName .
- docker tag $imageName $ecr:latest
- aws ecr get-login-password --region $region | docker login --username AWS --password-stdin $account.dkr.ecr.$region.amazonaws.com
- docker push $ecr
- echo going to update lambda
- aws --version
- echo $lambdaFunctionName
- echo $ecr
- aws lambda update-function-code --function-name $function_name --image-uri $ecr:latest
如何更新代码管道使用的 AWS cli 版本和/或修改我的
update-function-code
命令以与 AWS CLI 1.18 兼容
但是更新 lambda 代码命令失败,并显示以下内容:
usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:
aws help
aws <command> help
aws <command> <subcommand> help
Unknown options: --image-uri,
我相信这是因为代码构建管道正在运行旧版本的 AWS CLI。我知道这一点是因为我也在 YAML 文件中打印出了
aws --version
aws-cli/1.18.49 Python/3.7.6 Linux/4.14.291-218.527.amzn2.x86_64 exec-env/AWS_ECS_EC2 botocore/1.15.49
更新:
我按照此处的说明下载了 AWS CLI 版本 1.18,当我查看手册页时,我发现 image-uri 不受支持:
NAME
update-function-code -
DESCRIPTION
Updates a Lambda function's code.
The function's code is locked when you publish a version. You can't
modify the code of a published version, only the unpublished version.
See also: AWS API Documentation
See 'aws help' for descriptions of global parameters.
SYNOPSIS
update-function-code
--function-name <value>
[--zip-file <value>]
[--s3-bucket <value>]
[--s3-key <value>]
[--s3-object-version <value>]
[--publish | --no-publish]
[--dry-run | --no-dry-run]
[--revision-id <value>]
[--cli-input-json <value>]
[--generate-cli-skeleton <value>]
所以我要么需要更新我的管道以将捆绑资源部署到 S3,然后更新 lambda 函数,要么找到一种方法来更新我的管道使用的 CLI 版本
我了解到可以指定构建环境使用的图像。您可以在构建阶段从 CodeBuild->Build->Build Projects->Edit->Environments 中手动指定它。
当我打开它时,我了解到我的构建正在使用
“aws/codebuild/amazonlinux2-aarch64-standard:1.0”
。您可以通过“覆盖图像”指定要使用的更新版本
在我的 CDK 代码中,我通过
指定了此覆盖 const pipelineProject = new codebuild.PipelineProject(this, `${props.lambdaFunctionName}-pipelineProject`, {
...etc... etc...
environment: {
buildImage: LinuxArmBuildImage.AMAZON_LINUX_2_STANDARD_3_0
}
});
完成此更改后,我能够确认有更新的 CLI 版本
aws-cli/2.11.11 Python/3.11.2 Linux/4.14.311-233.529.amzn2.aarch64 exec-env/AWS_ECS_EC2 exe/aarch64.amzn.2023 prompt/off