-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
(CDK CLI): cdk migrate produces incorrect types and casing #27473
Comments
Thanks for the report, I'm not really seeing the same behavior, but I am seeing some more obvious issues crop up. Here's the output for my stack file after deploying a RestApi just adding the GET method import * as cdk from 'aws-cdk-lib';
import * as apigateway from 'aws-cdk-lib/aws-apigateway';
import * as cdk from 'aws-cdk-lib/aws-cdk';
export interface BucketStackStackProps 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 BucketStackStack extends cdk.Stack {
public readonly restApiEndpoint0551178A;
public constructor(scope: cdk.App, id: string, props: BucketStackStackProps = {}) {
super(scope, id, props);
// Applying default props
props = {
...props,
bootstrapVersion: new cdk.CfnParameter(this, 'BootstrapVersion', {
type: 'AWS::SSM::Parameter::Value<String>',
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 cdkMetadata = new cdk.CfnMetadata(this, 'CDKMetadata', {
analytics: 'v2:deflate64:H4sIAAAAAAAA/02Oyw7CIBBFv8U9jI+FpksfW2NSP8AgjJU+gJTBpmn674Jo4mrOnLm5mQ0UBawWYvBcqoa3+g7TlYRsWFQ34XQlCAcxwlSip73T7PgwPzyha+3YoaFk/7bYUGFyGWLehl7iQXhkZ6SnVemYaU54CeQCfbs/2ZkZqxBqv3ytt7CLP9Zea94HQ7pDKPN8A60Sika/AAAA',
});
cdkMetadata.cfnOptions.metadata = {
aws:cdk:path: 'BucketStack/CDKMetadata/Default',
};
const restApi0C43bf4b = new apigateway.CfnRestApi(this, 'RestApi0C43BF4B', {
name: 'RestApi',
});
restApi0C43bf4b.cfnOptions.metadata = {
aws:cdk:path: 'BucketStack/RestApi/Resource',
};
if (restApi0C43bf4b == null) { throw new Error(`A combination of conditions caused 'restApi0C43bf4b' to be undefined. Fixit.`); }
const restApiGet0f59260b = new apigateway.CfnMethod(this, 'RestApiGET0F59260B', {
authorizationType: 'NONE',
httpMethod: 'GET',
integration: {
type: 'MOCK',
},
resourceId: restApi0C43bf4b.attrRootResourceId,
restApiId: restApi0C43bf4b.ref,
});
restApiGet0f59260b.cfnOptions.metadata = {
aws:cdk:path: 'BucketStack/RestApi/Default/GET/Resource',
};
if (restApi0C43bf4b == null) { throw new Error(`A combination of conditions caused 'restApi0C43bf4b' to be undefined. Fixit.`); }
if (restApiGet0f59260b == null) { throw new Error(`A combination of conditions caused 'restApiGet0f59260b' to be undefined. Fixit.`); }
const restApiDeployment180Ec503e517d3375a1c04758a7a4b777a070851 = new apigateway.CfnDeployment(this, 'RestApiDeployment180EC503e517d3375a1c04758a7a4b777a070851', {
description: 'Automatically created by the RestApi construct',
restApiId: restApi0C43bf4b.ref,
});
restApiDeployment180Ec503e517d3375a1c04758a7a4b777a070851.cfnOptions.metadata = {
aws:cdk:path: 'BucketStack/RestApi/Deployment/Resource',
};
restApiDeployment180Ec503e517d3375a1c04758a7a4b777a070851.addDependency(restApiGet0f59260b);
if (restApi0C43bf4b == null) { throw new Error(`A combination of conditions caused 'restApi0C43bf4b' to be undefined. Fixit.`); }
if (restApiDeployment180Ec503e517d3375a1c04758a7a4b777a070851 == null) { throw new Error(`A combination of conditions caused 'restApiDeployment180Ec503e517d3375a1c04758a7a4b777a070851' to be undefined. Fixit.`); }
const restApiDeploymentStageprod3855De66 = new apigateway.CfnStage(this, 'RestApiDeploymentStageprod3855DE66', {
deploymentId: restApiDeployment180Ec503e517d3375a1c04758a7a4b777a070851.ref,
restApiId: restApi0C43bf4b.ref,
stageName: 'prod',
});
restApiDeploymentStageprod3855De66.cfnOptions.metadata = {
aws:cdk:path: 'BucketStack/RestApi/DeploymentStage.prod/Resource',
};
// Outputs
this.restApiEndpoint0551178A = [
'https://',
restApi0C43bf4b.ref,
'.execute-api.us-east-1.',
this.urlSuffix,
'/',
restApiDeploymentStageprod3855De66.ref,
'/',
].join('');
new cdk.CfnOutput(this, 'RestApiEndpoint0551178A', {
value: this.restApiEndpoint0551178A!.toString(),
});
}
} This is experimental, so naturally there's still a lot of work to be done here 🙂 |
We are starting from a SAM template and defining the API mostly through the Function event sources -- maybe the cause of the differences? |
If you could share a sample template to reproduce exactly what you see that'd be great |
The issue here was how we were handling json. This should now be fixed. @rogerchi please let us know. if this is not the case. |
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
Describe the bug
The generated
CfnRestApi
construct from acdk migrate
command incorrectly translates some of the property keys.body.paths.{resource}.{verb}.responses.{code}
-code
should be a string, but translated as numberbody.paths.{resource}.{verb}.responses.{code}.headers
- all headers here have been converted to camelCase instead of remaining kebab-casebody.paths.{resource}.xAmazonApigatewayIntegration
- should bex-amazon-apigateway-integration
body.paths.{resource}.xAmazonApigatewayIntegration.requestTemplates
- the templates in here are camelCased (e.g.applicationJson
, but should be string keys likeapplication/json
body.paths.{resource}.xAmazonApigatewayIntegration.responses.default.responseTemplates
- the templates in here are camelCased (e.g.applicationJson
, but should be string keys likeapplication/json
body.paths.{resource}.xAmazonApigatewayIntegration.responses.default.responseParameters
- the properties in here look to refer to amethod
variable, e.g.method.response.header.AccessControlAllowOrigin: '\'*\'',
, but instead should be string keys:'method.response.header.Access-Control-Allow-Origin': '\'*'\'',
Expected Behavior
Some of these properties should be string keys, not converted to camelCase
Current Behavior
Example output:
Reproduction Steps
Run
cdk migrate
against an existing stack with a RestApiPossible Solution
Set these properties to strings instead of converting them to camelCase
Additional Information/Context
No response
CDK CLI Version
2.100.0
Framework Version
No response
Node.js Version
v18.18.0
OS
MacOS
Language
TypeScript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: