azure - 尝试在 Azure DevOps 管道 shell 中运行 "InvalidSignatureException"命令时获取 "aws ecr-get-login-password"

标签 azure azure-devops amazon-ecr

我想要构建 Docker 镜像并将其从 Azure DevOps 部署到 AWS ECR。

我遵循了本教程 - https://www.devguides.dev/how-to-build-and-deploy-docker-images-from-azure-devops-to-aws-ecr/

我不断收到以下错误: 调用GetAuthorizationToken操作时发生错误(InvalidSignatureException):我们计算的请求签名与您提供的签名不匹配。检查您的 AWS secret 访问 key 和签名方法。有关详细信息,请参阅服务文档。

我已使用相同的 AWS 访问 key 和 key 在本地手动检查并运行了“aws ecr-get-login-password”命令,它确实返回了临时密码,因此我知道权限和 key 是正确的。

我验证了我设置的变量是否正确,并且通过将它们打印出来供我在 Azure bash shell 中查看来读取它们 - 它们是正确的。

有什么建议吗?

我需要在 Azure 中的其他位置提供 AWS 登录信息吗?

下面是管道构建 yaml:

trigger:
  branches:
    include:
    - build-and-push-azure-to-aws

pool:
  vmImage: 'ubuntu-latest'

variables:
  - group: dev
  - name: DOCKER_REPOSITORY
    value: $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com/$(DOCKER_REPOSITORY_NAME)

steps:
- script: |
    aws ecr get-login-password --region $(AWS_REGION) | docker login --username AWS --password-stdin $(AWS_ACCOUNT_ID).dkr.ecr.$(AWS_REGION).amazonaws.com
  displayName: 'Login to AWS'
  env:
    AWS_ACCESS_KEY_ID: $(AWS_ACCESS_KEY_ID)
    AWS_SECRET_ACCESS_KEY: $(AWS_SECRET_ACCESS_KEY)

- task: Docker@2
  displayName: Build docker image
  inputs:
    repository: $(DOCKER_REPOSITORY)
    command: buildAndPush
    Dockerfile: Dockerfile
    tags: |
      latest

这是我得到的错误:


==============================================================================
Task         : Command line
Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version      : 2.164.2
Author       : Microsoft Corporation
Help         : https://learn.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
========================== Starting Command Output ===========================
/bin/bash --noprofile --norc /home/vsts/work/_temp/043d91c2-1246-45f3-909b-6594561cfbf1.sh

An error occurred (InvalidSignatureException) when calling the GetAuthorizationToken operation: The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.

最佳答案

如果您想要构建并部署从 Azure DevOps 到 AWS ECR 的 Docker 镜像,您可以使用一组有效的 AWS 凭证创建与 AWS 的服务连接。您可以关注此文档 AWS Toolkit for Azure DevOps获取设置此服务连接的更多详细信息。

enter image description here

然后使用 Amazon ECR Push 任务将 Docker 镜像推送到 AWS 上的 Amazon Elastic Container Registry。

enter image description here

您可以查看下面的博客以获取更多详细信息:

https://aws.amazon.com/blogs/devops/deploying-a-asp-net-core-web-application-to-amazon-ecs-using-an-azure-devops-pipeline/

关于azure - 尝试在 Azure DevOps 管道 shell 中运行 "InvalidSignatureException"命令时获取 "aws ecr-get-login-password",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62958269/

相关文章:

c# - 为 Azure 订阅日志使用证书 - 403 禁止

amazon-web-services - AWS ECS 网络 ACL 要求

azure - Azure ARM 中负载均衡器的入站 NAT 规则,如何指定端口范围?

azure - 如何检索生成的 Azure Key Vault 证书的 PFX 密码?

c# - 如何在计时器触发的函数上强制执行单例行为?

node.js - 如何将 Azure DevOps 构建管道连接到专用终结点

azure-devops - 如何检索用于 Azure Dev-Ops Analytics Velocity Dashboard Widget 的 Velocity 数据?

Azure create servicePrincipal 结果“一个或多个属性包含无效值”

amazon-web-services - 如何更改 SageMaker Docker 容器的共享内存?

aws-cloudformation - Cloudformation - ECS 服务。如何在没有堆栈冲突的情况下管理管道部署的镜像更新