aws / chalice

Python Serverless Microframework for AWS
Apache License 2.0
10.67k stars 1.01k forks source link

Is there a way to extract Rest Api Id from chalice cdk. #2024

Closed patelhpr closed 1 year ago

patelhpr commented 1 year ago

Hi,

I am developing a rest api using Chalice, and I have to use that api in the frontend of a web application. I need that rest api id and domain to pass it on to my frontend as an environment variable when I create my infrastructure. I am using CDK to create rest of the infrastructure as well. I was wondering if there is any way I can extract that from the CDK.

I tried doing something like this but it only gives a CDK Reference object and not the actual rest api id.

rest_api_id = self.chalice.get_resource("RestAPI").get_att("RestApiId")

Any help would be appreciated,

Thanks in Advance

manikyab commented 1 year ago

@patelhpr you can try using the cdk --outputs-file parameter to get the output in json file when using 'cdk deploy' . It will give you RestAPI in JSON and later you can use the same for your frontend deployment.

jdalzatec commented 1 year ago

You were very close! This works:

rest_api_id = self.chalice.get_resource("RestAPI").get_att("RestApiId").to_string()