Reid
Reid

Reputation: 4524

AWS Cloudformation / Codepipeline Parameters: [ProjectId] must have values

I am trying to create a simple (for now) cloud formation/code pipeline integration, but I am getting an error when generating a changeset for cloudformation.

I have my code pipeline building the output YML (template below) using the code: - aws cloudformation package --template template.json --s3-bucket $S3_BUCKET --output-template template-export.yml that export then goes into the cloud formation to create a changeset.

When it trys to create the changeset, I get this error Parameters: [ProjectId] must have values (Service: AmazonCloudFormation; Status Code: 400; Error Code: ValidationError; Request ID: 4d20b24f-fd8b-11e8-9014-599dd1a18437)

What is going wrong?

Input template.json

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Parameters": {
    "ProjectId": {
      "Type": "String",
      "Description": "Codepipeline cloudformation test"
    },
    "Stage": {
      "Default": "",
      "Type": "String",
      "Description": "I am guessing some thing goes here"
    }
  },
  "Resources": {
    "LambdaExecutionRole": {
      "Type": "AWS::IAM::Role",
      "Description": "Creating service role in IAM for AWS Lambda",
      "Properties": {
        "RoleName": {
          "Fn::Sub": "CodeStar-${ProjectId}-Execution${Stage}"
        },
        "AssumeRolePolicyDocument": {
          "Statement": [{
            "Action": "sts:AssumeRole",
            "Effect": "Allow",
            "Principal": {
              "Service": [
                "lambda.amazonaws.com"
              ]
            }
          }]
        },
        "ManagedPolicyArns": [
          "arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole"
        ],
        "Path": "/"
      }
    },
    "CreateUser": {
      "Type": "AWS::Lambda::Function",
      "Properties": {
        "Handler": "API/CreateUser.handler",
        "Code": "API/CreateUser.py",
        "Role": {
          "Fn::GetAtt": [
            "LambdaExecutionRole",
            "Arn"
          ]
        },
        "Runtime": "python2.7",
      }
    }
  }

}

Output from codebuild template-export.yml

AWSTemplateFormatVersion: '2010-09-09'
Parameters:
  ProjectId:
    Description: Codepipeline cloudformation test
    Type: String
  Stage:
    Default: ''
    Description: I am guessing some thing goes here
    Type: String
Resources:
  CreateUser:
    Properties:
      Code:
        S3Bucket: xxxx
        S3Key: xxxx
      Handler: API/CreateUser.handler
      Role:
        Fn::GetAtt:
        - LambdaExecutionRole
        - Arn
      Runtime: python2.7
    Type: AWS::Lambda::Function
  LambdaExecutionRole:
    Description: Creating service role in IAM for AWS Lambda
    Properties:
      AssumeRolePolicyDocument:
        Statement:
        - Action: sts:AssumeRole
          Effect: Allow
          Principal:
            Service:
            - lambda.amazonaws.com
      ManagedPolicyArns:
      - arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
      Path: /
      RoleName:
        Fn::Sub: CodeStar-${ProjectId}-Execution${Stage}
    Type: AWS::IAM::Role

Other Info:

Cloudformation is using IAM with full admin privilages. allow *

Generate Changeset Settings:

Upvotes: 1

Views: 6937

Answers (1)

user10775237
user10775237

Reputation:

Your issue here is that you haven't passed a value to the ProjectId parameter inside your cloudformation template, if you look at the snippet of your template here:

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Parameters": {
    "ProjectId": {
      "Type": "String",
      "Description": "Codepipeline cloudformation test"
    },
    "Stage": {
      "Default": "",
      "Type": "String",
      "Description": "I am guessing some thing goes here"
    }
  },

You have given the parameter Stage a default value, whereas ProjectId doesn't have any default value, meaning that if you do not specify in your CLI command what you want the ProjectId value to be then it will be nothing which will result in a Validation failure as it's expecting there to be a string against that parameter when in reality the value is None.

If you do this instead:

{
  "AWSTemplateFormatVersion": "2010-09-09",
  "Parameters": {
    "ProjectId": {
      "Default": "",
      "Type": "String",
      "Description": "Codepipeline cloudformation test"
    },
    "Stage": {
      "Default": "",
      "Type": "String",
      "Description": "I am guessing some thing goes here"
    }
  },

It means the entry will be an empty string but the cloudformation template shouldn't fail validation any longer.

Upvotes: 4

Related Questions