Aws-cdk: Fifo queue without name in nested stack fails to create

Created on 18 Jan 2020  路  5Comments  路  Source: aws/aws-cdk

Reproduction Steps

import cdk = require('@aws-cdk/core');

import { NestedStack } from '@aws-cdk/aws-cloudformation';
import { Queue } from '@aws-cdk/aws-sqs';

export class CdkFifoQueueStack extends cdk.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    new MyNestedStack(this, 'NestedStack');
  }
}

export class MyNestedStack extends NestedStack {
  constructor(scope: cdk.Construct, id: string) {
    super(scope, id);

    new Queue(this, 'MyQueue', {
      fifo: true
    });
  }
}

source

MUST USE cdk deploy. THE STACK SYNTHESIZES FINE.

Error Log

CloudFormation error after running cdk deploy:

The name of a FIFO queue can only include alphanumeric characters, hyphens, or underscores, must end with .fifo suffix and be 1 to 80 in length. (Service: AmazonSQS; Status Code: 400; Error Code: InvalidParameterValue; Request ID: 0079e079-6bf5-5eec-90d9-b6e4eebec170)

Environment

  • CLI Version : 1.19.0
  • Framework Version: 1.19.0
  • OS : macOS
  • Language : TypeScript

This is :bug: Bug Report

@aws-cdaws-sqs bug efformedium p1

Most helpful comment

The queue name is it's physical ID, when not required, the CDK will not set it, unless provided by the user. Setting a physical name for a resource have implication on the resource update policy, from CloudFormation docs:

If you specify a name, you can't perform updates that require replacement of this resource. You can perform updates that require no or some interruption. If you must replace the resource, specify a new name.

Which is why we try to avoid setting a physical name for resources when not required. We will follow up with CloudFormation to see if this can be fixed on their side.

In the meantime we can implement @nija-at suggestion above.

All 5 comments

If a queue name is not specified, CloudFormation generates a unique physical ID and uses that ID for the queue name. The generated name will include the containing stack name and the queue resource logical id. To adhere to SQS queue name limitations of max 80 characters CloudFormation will trim the stack name and logical id components in the generated physical ID. When the queue is a fifo queue CloudFormation will append .fifo to the physical ID as required by SQS which might result in a queue name longer than the max 80 characters :/ causing it to fail.

Nested stacks names (generated by CloudFormation) are composed from the parent stack name and the nested stack resource logical ID, resulting in a longer than the average user generated stack name, making fifo queue defined inside a nested stack more likely to hit the max 80 character limit.

I'm not quite sure what is the best way for the CDK to make this experience better for users as it seems the only way to make sure this will not happen is to make the queue name required and add verification which is a breaking change.
@eladb, any thoughts?

How about setting the queueName to ${this.node.uniqueId.substr(0, 75)}.fifo when the fifo flag is set to true?

Just got bit by that too.

Worse yet, the log output doesn't actually tell you what the problem was. Just says "resources could not be created".

And when you go into AWS, the NestedStack is deleted and is hidden.

So for AWS noobs like myself, it's many rabbit holes to go through to find what is wrong.

The queue name is it's physical ID, when not required, the CDK will not set it, unless provided by the user. Setting a physical name for a resource have implication on the resource update policy, from CloudFormation docs:

If you specify a name, you can't perform updates that require replacement of this resource. You can perform updates that require no or some interruption. If you must replace the resource, specify a new name.

Which is why we try to avoid setting a physical name for resources when not required. We will follow up with CloudFormation to see if this can be fixed on their side.

In the meantime we can implement @nija-at suggestion above.

And when you go into AWS, the NestedStack is deleted and is hidden.

yep, I get the nested stack id using the AWS cli and use the id in the console URL to view events via the console.

Can also view the events with the AWS cli.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

peterdeme picture peterdeme  路  3Comments

kawamoto picture kawamoto  路  3Comments

NukaCody picture NukaCody  路  3Comments

PaulMaddox picture PaulMaddox  路  3Comments

eladb picture eladb  路  3Comments