Read CloudFormation stack API Gateway output in AWS CDK app

Viewed 398

It is possible to read CloudFormation stack outputs via the CLI like so:

aws cloudformation describe-stacks --stack-name TestStack --query "Stacks[0].Outputs[?OutputKey=='TestAPIGatewayEndpoint'].OutputValue" --output text

How can I do this in a CDK app using the Constructs Library? Specifically, I am trying to get the API Gateway endpoint from a deployed stack and pass that to a web app in another stack.

1 Answers

Better use SSM to store and update endpoints, create an SSM in your CF template, with the value of Api Gateway endpoint, and in other stack use that SSM

Like in your resources

ApiEndPointConfig:
      Type: AWS::SSM::Parameter
      Properties:
        Name: /serverless/api-endpoint-config
        Type: String
        Value: !Sub "https://${apiGateway}.execute-api.${AWS::Region}.amazonaws.com/${apiGatewayStageName}"

Or you can use output parameter to extract api gateway url like

Outputs:
  ApiEndPoint:
    Description: "API endpoint"
    Value: !Sub "https://${apiGateway}.execute-api.${AWS::Region}.amazonaws.com/${apiGatewayStageName}"

I think you can't extract directly from CF stack, you have to use output parameter or SSM

Related