Solving CloudFormation Parameters are missing a value Error in CDK

avatar

Borislav Hadzhiev

Fri Apr 16 20212 min read

banner

Photo by Sage Friedman

Parameters missing a value in CDK #

CDK gets compiled down to CloudFormation before deployment, so we are able to use CloudFormation Parameters in CDK.

Parameters are key value pairs that we pass into the CDK stack at deployment time.

Parameter keys can only contain alphanumeric values [A-Za-z0-9]. CDK will strip all non alphanumeric values in parameter keys automatically.

The cause of the Error #

The cause of the "CloudFormation Parameters are missing a value" error in CDK, is that we have defined Parameters for which we didn't provide values when we tried to deploy.

For example:

export class MyCdkStack extends cdk.Stack { constructor(scope: cdk.App, id: string, props: cdk.StackProps) { super(scope, id, props); const s3Bucket = new s3.Bucket(this, 'avatars-bucket', { removalPolicy: cdk.RemovalPolicy.DESTROY, }); // ๐Ÿ‘‡ Defining a Parameter const bucketName = new cdk.CfnParameter(this, 'bucketName', { type: 'String', description: 'The name of the S3 bucket', }); } }

In the code snippet we've defined a Parameter, using the CfnParameter construct.

I'll now try to deploy my stack:

shell
npx cdk deploy

After issuing the command, I get the Error:

The following CloudFormation Parameters are missing a value: bucketName

parameters missing error

Resolving the Error #

In order to resolve the "CloudFormation Parameters are missing a value" error, we have to provide the necessary parameters via the --parameters flag when deploying.

For example:

shell
npx cdk deploy my-cdk-stack \ --parameters bucketName=avatars-bucket

This resolves the error and we are able to deploy our CDK stack successfully.

If you have multiple parameters, you have to specify the --parameters flag for each one:

shell
npx cdk deploy my-cdk-stack \ --parameters bucketName=avatars-bucket \ --parameters env=development

Parameters can only be Alphanumeric #

Parameters in CDK derive their name from the id parameter we've passed to the CfnParameter construct and from their location within the stack.

Since parameters in CloudFormation are only allowed to contain alphanumeric [A-Za-z0-9] characters, if we specify an id that is non alphanumeric, all of the non alphanumeric characters will be stripped.

For example, let's specify a non alphanumeric id for our bucketName parameter:

// ๐Ÿ‘‡ BUCKET_NAME contains an underscore const bucketName = new cdk.CfnParameter(this, 'BUCKET_NAME', { type: 'String', description: 'The name of the S3 bucket', });

Since BUCKET_NAME contains an underscore it's not alphanumeric. I'll now try to deploy:

shell
npx cdk deploy \ --parameters BUCKET_NAME=myBucket

The output shows an error:

Error: The following CloudFormation Parameters are missing a value: BUCKETNAME

non alphanumeric params

From the error message we can see that CDK automatically stripped all non alphanumeric characters from our parameter key.

To resolve the error, we have to remove all of the non alphanumeric characters from the parameter key and provide the the --parameters flag when deploying.

Further Reading #

Add me on LinkedIn

I'm a Web Developer with TypeScript, React.js, Node.js and AWS experience.

Let's connect on LinkedIn

Join my newsletter

I'll send you 1 email a week with links to all of the articles I've written that week

Buy Me A Coffee