Solving CloudFormation Parameters are missing a value Error in CDK

avatar

Borislav Hadzhiev

2 min

banner

Photo from Unsplash

# 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', }); } }

We defined a Parameter, using the CfnParameter construct.

I'll now try to deploy my stack:

shell
npx aws-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 aws-cdk deploy my-cdk-stack \ --parameters bucketName=avatars-bucket

This resolves the error and we can deploy our CDK stack successfully.

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

shell
npx aws-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 aws-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 --parameters flag when deploying.

# Further Reading

I wrote a book in which I share everything I know about how to become a better, more efficient programmer.
book cover
You can use the search field on my Home Page to filter through all of my articles.

Copyright ยฉ 2023 Borislav Hadzhiev