Open gentili opened 3 years ago
Distributor ID: Ubuntu
Description: Ubuntu 20.04.2 LTS
Release: 20.04
Codename: focal
I believe this is due to the schema definition the CDK uses not being correct (https://github.com/aws/aws-cdk/blob/master/packages/%40aws-cdk/cfnspec/spec-source/000_sam.spec.json), or possibly in the way that it validates references (there is no Stage
property on a AWS::Serverless::Api
but you can reference MyApi.Stage
).
The SAM template works if you deploy it on its own outside of the CDK, and the SAM documentation specifies how to reference the stage resource:
To reference the stage resource, use
<api-logical-id>.Stage
.
There's also more details in the docs for AWS CloudFormation resources generated when AWS::Serverless::Api is specified.
Ideally we can fix this upstream in the aws-cdk repo so I think it makes sense to file an issue there and see what they say.
The workaround says to comment a line in package.py. Where can I find this file? Can you please elaborate? Any help appreciated.
Thanks
@jbourjeli The file is wherever you pip installed the chalice package. Mine is in my virtual environment in lib/python3.9/site-packages/chalice/package.py
Thanks for noting this one. Its killing my cdk pipeline at the moment. Any resolution in sight?
also encountering this issue with cdk. the workaround indeed works, but perhaps someone found a different way that does not involve changing the source?
tried finding a way to reference RestAPI.Stage
and adding dependency but with no success
Steps to reproduce
output
The above exception was the direct cause of the following exception:
Traceback (most recent call last): File "app.py", line 6, in
ChaliceApp(app, 'cdktest')
File "/home/gentili/.virtualenvs/concursion-infrastructure/lib/python3.8/site-packages/jsii/_runtime.py", line 83, in call
inst = super().call(*args, kwargs)
File "/mnt/c/Users/gentili/git/cdktest/infrastructure/stacks/chaliceapp.py", line 19, in init
self.chalice = Chalice(
File "/home/gentili/.virtualenvs/concursion-infrastructure/lib/python3.8/site-packages/jsii/_runtime.py", line 83, in call
inst = super().call(*args, *kwargs)
File "/home/gentili/.virtualenvs/concursion-infrastructure/lib/python3.8/site-packages/chalice/cdk/construct.py", line 77, in init
self.sam_template = cloudformation_include.CfnInclude(
File "/home/gentili/.virtualenvs/concursion-infrastructure/lib/python3.8/site-packages/jsii/_runtime.py", line 83, in call
inst = super().call(args, kwargs)
File "/home/gentili/.virtualenvs/concursion-infrastructure/lib/python3.8/site-packages/aws_cdk/cloudformation_include/init.py", line 396, in init
jsii.create(CfnInclude, self, [scope, id, props])
File "/home/gentili/.virtualenvs/concursion-infrastructure/lib/python3.8/site-packages/jsii/_kernel/init.py", line 265, in create
response = self.provider.create(
File "/home/gentili/.virtualenvs/concursion-infrastructure/lib/python3.8/site-packages/jsii/_kernel/providers/process.py", line 347, in create
return self._process.send(request, CreateResponse)
File "/home/gentili/.virtualenvs/concursion-infrastructure/lib/python3.8/site-packages/jsii/_kernel/providers/process.py", line 329, in send
raise JSIIError(resp.error) from JavaScriptError(resp.stack)
jsii.errors.JSIIError: Element used in Ref expression with logical ID: 'RestAPI.Stage' not found
The generated sam.json file references
RestAPI.Stage
when no correspondingAWS::ApiGateway::Stage
resource has been specified.Workaround
comment out
'Stage': {'Ref': 'RestAPI.Stage'},