amazon-web-servicesaws-cloudformationaws-codepipeline

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


This is my codepipeline deploy stage:

- 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

The exact error I am getting is

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)

How can I resolve this issue? Is there any other way we can pass the parameter values to cloudformation template?


Solution

  • TLDR; You have too many environment variables / the cumulative length of their content is too long.

    I just hit this arcane error msg myself. The less than or equal to 1000 part of the error message is the give away. It appears to be related to having too many environment variables.

    Suggestions:

    1. Validate that this is the problem by removing all but one of your environment variables. See if that works. If it does then it's highly likely that you need to figure out how to trim down the number of environment variables you are creating as part of the pipeline IaC.

    2. The less elegant solution that I've had to settle on is to export some values as Cfn Outputs. These values can then be looked up from within the buildspec.yml file using the AWS CLI. From there you can export them as environment variables.

    Example to lookup an SSM parameter name from the output of a CloudFormation template, and to then retrieve the value of the parameter from 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)"
    

    Using the above code, if you can find environment variables that you can export the value of from your CloudFormation template (rather than defining them as environment variables directly within the CodeBuild IaC), then you can use the pre_build phase of your buildspec.yml to turn them into environment variables. Obviously this is less than ideal.