aws / aws/aws-cdk-cli

cdk migrate cannot deal with CDK Stacks

Open
#458 0 comments 0 reactions 0 assignees View on GitHub
bug p1
Dominant language
TypeScript
Stars
105
Forks
122
Avg merge
1d 17h
Merged PRs (30d)
71

Description

`cdk migrate --from-stack --stack-name AppStack`

`AppStack` is the default stack as created by `cdk init`

First failure:

```
❌ Migrate failed for `AppStack`: AppStackStack could not be generated because Analytics is not a valid property for resource CDKMetadata of type AWS::CDK::Metadata
```

Deployed the stack again with `--no-version-reporting`. Then the migrate command works but generated code contains this (including syntax errors):

```ts
import * as cdk from 'aws-cdk-lib';
import * as sns from 'aws-cdk-lib/aws-sns';
import * as sqs from 'aws-cdk-lib/aws-sqs';

export interface AppStackStackProps extends cdk.StackProps {
/**
* Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]
* @default '/cdk-bootstrap/hnb659fds/version'
*/
readonly bootstrapVersion?: string;
}

export class AppStackStack extends cdk.Stack {
public constructor(scope: cdk.App, id: string, props: AppStackStackProps = {}) {
super(scope, id, props);

// Applying default props
props = {
...props,
bootstrapVersion: new cdk.CfnParameter(this, 'BootstrapVersion', {
type: 'AWS::SSM::Parameter::Value',
default: props.bootstrapVersion?.toString() ?? '/cdk-bootstrap/hnb659fds/version',
description: 'Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]',
}).valueAsString,
};

// Resources
const appQueueFd3f4958 = new sqs.CfnQueue(this, 'AppQueueFD3F4958', {
visibilityTimeout: 300,
});
appQueueFd3f4958.cfnOptions.metadata = {
aws:cdk:path: 'AppStack/AppQueue/Resource',
};
appQueueFd3f4958.cfnOptions.deletionPolicy = cdk.CfnDeletionPolicy.DELETE;

const appTopic115Ea044 = new sns.CfnTopic(this, 'AppTopic115EA044', {
});
appTopic115Ea044.cfnOptions.metadata = {
aws:cdk:path: 'AppStack/AppTopic/Resource',
};

const appQueuePolicyBd4f9387 = new sqs.CfnQueuePolicy(this, 'AppQueuePolicyBD4F9387', {
policyDocument: {
Statement: [
{
Action: 'sqs:SendMessage',
Condition: {
ArnEquals: {
'aws:SourceArn': appTopic115Ea044.ref,
},
},
Effect: 'Allow',
Principal: {
Service: 'sns.amazonaws.com',
},
Resource: appQueueFd3f4958.attrArn,
},
],
Version: '2012-10-17',
},
queues: [
appQueueFd3f4958.ref,
],
});
appQueuePolicyBd4f9387.cfnOptions.metadata = {
aws:cdk:path: 'AppStack/AppQueue/Policy/Resource',
};

const appQueueAppStackAppTopic352A2f0bba0ff351 = new sns.CfnSubscription(this, 'AppQueueAppStackAppTopic352A2F0BBA0FF351', {
endpoint: appQueueFd3f4958.attrArn,
protocol: 'sqs',
topicArn: appTopic115Ea044.ref,
});
appQueueAppStackAppTopic352A2f0bba0ff351.cfnOptions.metadata = {
aws:cdk:path: 'AppStack/AppQueue/AppStackAppTopic352A2F0B/Resource',
};
appQueueAppStackAppTopic352A2f0bba0ff351.addDependency(appQueuePolicyBd4f9387);
}
}

```

Few things to note here:

A/ the generated code should not have syntax errors
B/ we should skip the CDK path metadata anyway
C/ we should probably not include the `BootstrapVersion` parameter

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.