Skip to content
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 tutorial does not work [Value of property Types must be of type List of String] #1764

Open
ishihara1989 opened this issue Jul 7, 2021 · 8 comments

Comments

@ishihara1989
Copy link

I followed the steps in official CDK tutorials but couldn't make it work.
Cloudformation detected some type errors, but according to AWS documents, AWS::ApiGateway::RestApi doesn't have property Types.
I don't know if this is because of my setups. I suspect some Cloudformation APIs have changed.
Are there any workaround for this?

Steps to reproduce

# chalice new-project


   ___  _  _    _    _     ___  ___  ___
  / __|| || |  /_\  | |   |_ _|/ __|| __|
 | (__ | __ | / _ \ | |__  | || (__ | _|
  \___||_||_|/_/ \_\|____||___|\___||___|


The python serverless microframework for AWS allows
you to quickly create and deploy applications using
Amazon API Gateway and AWS Lambda.

Please enter the project name
[?] Enter the project name: testing
[?] Select your project type: [CDK] Rest API with a DynamoDB table
   REST API
   S3 Event Handler
   Lambda Functions only
   Legacy REST API Template
 > [CDK] Rest API with a DynamoDB table
# cd testing/
# python3 -m pip install -r requirements.txt
# cd infrastructure/
# cdk bootstrap
# cdk deploy
Creating deployment package.
Reusing existing deployment package.
testing: deploying...
[0%] start: Publishing 2bbd148710893c0c814ea4eeff54b84f586a012739c8a7babb10c0b041bc4f8f:current
[100%] success: Published 2bbd148710893c0c814ea4eeff54b84f586a012739c8a7babb10c0b041bc4f8f:current
testing: creating CloudFormation changeset...
6:54:59 AM | CREATE_FAILED        | AWS::ApiGateway::RestApi  | RestAPI
Value of property Types must be of type List of String

        Function._fromCloudFormation (/tmp/jsii-kernel-hoLwjr/node_modules/@aws-cdk/aws-sam/lib/sam.generated.js:171:21)
        \_ CfnInclude.getOrCreateResource (/tmp/jsii-kernel-hoLwjr/node_modules/@aws-cdk/cloudformation-include/lib/cfn-include.js:559:48)
        \_ new CfnInclude (/tmp/jsii-kernel-hoLwjr/node_modules/@aws-cdk/cloudformation-include/lib/cfn-include.js:68:18)
        \_ /tmp/tmp9texe7d7/lib/program.js:8154:58
        \_ Kernel._wrapSandboxCode (/tmp/tmp9texe7d7/lib/program.js:8582:24)
        \_ Kernel._create (/tmp/tmp9texe7d7/lib/program.js:8154:34)
        \_ Kernel.create (/tmp/tmp9texe7d7/lib/program.js:7895:29)
        \_ KernelHost.processRequest (/tmp/tmp9texe7d7/lib/program.js:9479:36)
        \_ KernelHost.run (/tmp/tmp9texe7d7/lib/program.js:9442:22)
        \_ Immediate._onImmediate (/tmp/tmp9texe7d7/lib/program.js:9443:46)
        \_ processImmediate (internal/timers.js:464:21)


 ❌  testing failed: Error: The stack named testing failed creation, it may need to be manually deleted from the AWS console: ROLLBACK_COMPLETE
    at Object.waitForStackDeploy (/usr/local/lib/node_modules/aws-cdk/lib/api/util/cloudformation.ts:305:11)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at Object.deployStack (/usr/local/lib/node_modules/aws-cdk/lib/api/deploy-stack.ts:294:26)
    at CdkToolkit.deploy (/usr/local/lib/node_modules/aws-cdk/lib/cdk-toolkit.ts:184:24)
    at initCommandLine (/usr/local/lib/node_modules/aws-cdk/bin/cdk.ts:213:9)
The stack named testing failed creation, it may need to be manually deleted from the AWS console: ROLLBACK_COMPLETE

Version information:

# cdk --version
1.111.0 (build 556ca93)
# chalice --version
chalice 1.23.0, python 3.8.6, linux 5.4.0-1029-aws
@DDynamic
Copy link

DDynamic commented Jul 7, 2021

I am having the same issue. I filed a ticket with AWS yesterday.

@DDynamic
Copy link

DDynamic commented Jul 7, 2021

The solution for now is to downgrade all cdk packages to 1.110.0.

@ishihara1989
Copy link
Author

OK, finally I found workaround.
Adding

rest_api = self.chalice.sam_template.get_resource('RestAPI')
rest_api.add_property_override('EndpointConfiguration', {
    'Type': 'EDGE'
})

to ChaliceApp.__init__ fixed the deploy issue..

@alexpulver
Copy link

H/t @skinny85 for the below information. There was a change in the AWS SAM specification that AWS CDK uses for automatically generating classes in the @aws-cdk/aws-sam module.

In this PR, the AWS::Serverless::Api definition changed from:

    "ResourceTypes": {
        "AWS::Serverless::Api": {
            "Properties": {
                "EndpointConfiguration": {
                    "Required": false,
                    "PrimitiveType": "String",
                    "UpdateType": "Immutable"
                },

to:

    "ResourceTypes": {
        "AWS::Serverless::Api": {
            "Properties": {
                "EndpointConfiguration": {
                    "Required": false,
                    "Type": "EndpointConfiguration",
                    "UpdateType": "Immutable"
                },

AWS Chalice still generates the AWS SAM template using the older AWS CloudFormation specification that uses "PrimitiveType": "String":

"Resources": {
  "RestAPI": {
    "Type": "AWS::Serverless::Api",
    "Properties": {
      "EndpointConfiguration": "EDGE",

It seems to break when AWS CDK cloudformation_include.CfnInclude parses the AWS SAM template because of the mismatch in AWS CloudFormation specification.

Perhaps AWS Chalice should be updated to produce the new AWS CloudFormation specification to avoid the need in the escape hatch.

@skinny85
Copy link

This is a little worrying.

The CDK takes the SAM spec from the GoFormation project. Apparently this change to the SAM spec was done in awslabs/goformation#376.

However, this would imply that the SAM folks made breaking change in their spec, which I hope is unlikely. Perhaps the correct type for that property should be a union between a string, and the EndpointConfiguration property type...?

@skinny85
Copy link

Hmm, the public SAM docs state:

EndpointConfiguration
The endpoint type of a REST API.

Type: EndpointConfiguration

Required: No

AWS CloudFormation compatibility: This property is similar to the EndpointConfiguration property of an AWS::ApiGateway::RestApi resource.
The nested configuration properties are named differently.

So maybe this really was a breaking change in SAM....?

@skinny85
Copy link

Confirmed with the SAM folks that this is actually incorrect in the docs, and that string is still allowed there.

I will patch this in the CDK.

@skinny85
Copy link

aws/aws-cdk#15526

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants