aws-lambda - 如何从 AWS Codepipeline 中的 json 文件读取值?

标签 aws-lambda aws-cloudformation aws-codepipeline aws-step-functions

我的问题:Codepipeline 如何读取 SourceCodeArtifact 中的 json 文件中的字段值?

我有 Gthub 存储库,其中包含一个文件 imageManifest.json,如下所示:

{
  "image_id": "docker.pkg.github.com/my-org/my-repo/my-app",
  "image_version": "1.0.1"
}

我希望我的 AWS Codepipeline Source 阶段能够从 imageManifest.json 读取 image_version 的值,并将其作为参数传递给后续的 CloudFormation 操作我的管道的阶段。

作为引用,这是我的源阶段。

        Stages:
        - Name: GitHubSource
          Actions:
          - Name: SourceAction
            ActionTypeId:
              Category: Source
              Owner: ThirdParty
              Version: '1'
              Provider: GitHub
            OutputArtifacts:
              - Name: SourceCodeArtifact
            Configuration:
              Owner: !Ref GitHubOwner
              Repo: !Ref GitHubRepo
              OAuthToken: !Ref GitHubAuthToken

这是我的部署阶段:

        - Name: DevQA
          Actions:
          - Name: DeployInfrastructure
            InputArtifacts:
              - Name: SourceCodeArtifact
            ActionTypeId:
              Category: Deploy
              Owner: AWS
              Provider: CloudFormation
              Version: '1'
            Configuration:
              StackName: !Ref AppName
              Capabilities: CAPABILITY_NAMED_IAM
              RoleArn: !GetAtt [CloudFormationRole, Arn]
              ParameterOverrides: !Sub '{"ImageId": "${image_version??}"}'

请注意,上面最后一行中的 image_version 只是我理想的占位符,用于说明我希望如何使用 image_version json 值。

Codepipeline 如何读取 SourceCodeArtifact 中 json 文件中字段的值? 步骤函数? lambda ?代码构建?

最佳答案

您可以在源阶段和部署阶段之间使用 CodeBuild 步骤。

在 CodeBuild 步骤中,从 SourceArtifact(由源阶段生成的工件)读取 image_version 并写入工件“模板配置”文件 1这是 CloudFormation 操作的配置属性。该文件可以保存 CloudFormation 堆栈的参数值。使用此文件代替您当前使用的 ParameterOverrides

关于aws-lambda - 如何从 AWS Codepipeline 中的 json 文件读取值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63172241/

相关文章:

amazon-web-services - AWS 云形成 : Resize a Redshift cluster

amazon-web-services - 如何调试由 CircleCI 编排的 Serverless 生成的 CloudFormation 模板

amazon-web-services - 需要从 AWS Devops 服务连接 Azure 基础设施。这真的可能吗?

python - 如何从 AWS Lambda API 网关返回字节数组?

amazon-web-services - 从 DynamoDB 中查找没有哈希和范围键的行并将其删除

amazon-web-services - 如何将 Glue/Athena/Quicksight 与 CloudFormation 结合使用

node.js - 从另一个 lambda 调用 lambda 时出现问题

node.js - AWS Lambda - 无法访问捆绑在层(Node.js)中的JS文件

amazon-web-services - AWS CodeBuild golang 构建失败