ActionConfiguration Map 值必须满足约束:[Member must have length less than or equal to 1000

ActionConfiguration Map value must satisfy constraint: [Member must have length less than or equal to 1000

这是我的代码管道部署阶段:

- Name: Deploy-Dev
  Actions:
    - Name: Deploy
      ActionTypeId:
        Category: Build
        Owner: AWS
        Version: 1
        Provider: CodeBuild
      InputArtifacts:
        - Name: MyCfnBuildSpec
        - Name: MyCfnCode
      Configuration:
        PrimarySource: MyCfnBuildSpec
        ProjectName: !Ref Deploy
        EnvironmentVariables: !Sub '[
        {"type":"PLAINTEXT","name":"APP", "value":"${ProjName}"},
        {"type":"PLAINTEXT","name":"APPENV", "value":"${AppEnv}"},
        {"type":"PLAINTEXT","name":"NEXUS_GROUP_ID", "value":"${NexusGroupId}"},
        {"type":"PLAINTEXT","name":"AWS_DEFAULT_REGION", "value":"${AWS::Region}"},
        {"type":"PLAINTEXT","name":"TENANT_ACC_ID", "value":"{{resolve:ssm:/delta/tooling/si/accountid:1}}"},
        {"type":"PLAINTEXT","name":"TEMPLATE_NAME", "value":"${CfnTemplateName}"},
        {"type":"PLAINTEXT","name":"LOCALCONTEXTPATH", "value":"${LocalContextPath}"},
        {"type":"PLAINTEXT","name":"ODEFlghtIID", "value":"${ODEFlghtIID}"},
        {"type":"PLAINTEXT","name":"ODEFlghtSecrt", "value":"${ODEFlghtSecrt}"},
        {"type":"PLAINTEXT","name":"ODEgateID", "value":"${ODEgateID}"},
        {"type":"PLAINTEXT","name":"ODEgateSecrt", "value":"${ODEgateSecrt}"},
        {"type":"PLAINTEXT","name":"MsgmngtID", "value":"${MsgmngtID}"},
        {"type":"PLAINTEXT","name":"MsgMngtsecrt", "value":"${MsgMngtsecrt}"},
        {"type":"PLAINTEXT","name":"GIT_COMMIT_ID", "value":"#{GitlabCustomSource.commit_id}"}]'
      RunOrder: 2

我得到的确切错误是

ActionConfiguration Map value must satisfy constraint: [Member must have length less than or equal to 1000, Member must have length greater than or equal to 1] (Service: AWSCodePipeline; Status Code: 400; Error Code: ValidationException; Request ID: c6fe0776-5582-4d0d-a95d-64f7bf34f87e; Proxy: null)

我该如何解决这个问题?有没有其他方法可以将参数值传递给 cloudformation 模板?

TLDR; 您的环境变量过多/内容累计长度过长。

我自己刚刚遇到了这个神秘的错误信息。错误消息的 小于或等于 1000 部分是赠品。好像跟环境变量太多有关

建议:

  1. 通过删除除一个环境变量以外的所有环境变量来验证这是问题所在。看看是否有效。如果是这样,那么您很可能需要弄清楚如何 trim 减少您作为管道 IaC 的一部分创建的环境变量的数量。

  2. 我不得不解决的不太优雅的解决方案是将一些值导出为 Cfn 输出。然后可以使用 AWS CLI 从 buildspec.yml 文件中查找这些值。从那里您可以将它们导出为环境变量。

从 CloudFormation 模板的输出中查找 SSM 参数名称,然后从 SSM 中检索参数值的示例。

  pre_build:
    commands:
      - export PrivateNPMUsernamePName="$(aws cloudformation describe-stacks --stack-name your-cloudformation-stack-name --region ${AWS_DEFAULT_REGION} --query "Stacks[0].Outputs[?ExportName=='privatenpmusername-name'].OutputValue" --output text)"
      - export PrivateNPMUsername="$(aws ssm get-parameters --names "${PrivateNPMUsernamePName}" --region ${AWS_DEFAULT_REGION} --query "Parameters[0].Value" --output text)"

使用上面的代码,如果您可以找到可以从 CloudFormation 模板中导出值的环境变量(而不是直接在 CodeBuild IaC 中将它们定义为环境变量),那么您可以使用 pre_build 阶段 buildspec.yml 将它们变成环境变量。显然这不太理想。