How can I get API Gateway

I’m creating a resource and need to get the gateway address for the CDN

How can I get DomainName?

Type: AWS::CloudFront::Distribution
Properties:
  DistributionConfig:
    Origins:
    - DomainName: address.execute-api.us-east-1.amazonaws.com 

First, you would need to add an output for the distribution to the Outputs section of your serverless.yml.

Then after deploying you can run sls info --verbose and you’ll see the CloudFront Distribution URL in the CLI.

You should be able to reconstruct the hostname using Serverless variables and CloudFormation. Something like this will probably work.

Type: AWS::CloudFront::Distribution
Properties:
DistributionConfig:
Origins:
- DomainName: { “Fn::Join” : [“”, [ “”, { “Ref” : “ApiGatewayRestApi” }, “.execute-api.${self:custom.region}.amazonaws.com” ] ] }

Note: This is untested and may contain bugs

I use something similar to pass the API GW URL as an environment variable to my Lambda. There’s a better write up here.