I’m trying to deploy CloudFront together with my function to have the CDN capabilities in front of my API. I do this by adding Cloudfront as a resource to my serverless.yml, and referencing the Origin via the API Gateway Domain:
frameworkVersion: '3' provider: name: aws resources: Resources: CloudFrontDistribution: Type: AWS::CloudFront::Distribution Properties: DistributionConfig: Origins: - Id: ApiGateway DomainName: Fn::Join: - "." - - Ref: ApiGatewayRestApi - execute-api - Ref: AWS::Region - amazonaws.com ... functions: hello: handler: handler.hello events: - httpApi: path: / method: get
The problem is that
Ref: ApiGatewayRestApi doesn’t work. All I get is an error:
The CloudFormation template is invalid: Template format error: Unresolved resource dependencies [ApiGatewayRestApi] in the Resources block of the template
If I hardcode the ID, the deployment works. How can I access the API Gateway ID within the resources? AFAIK the variable is defined here Serverless Framework - AWS Lambda Guide - AWS Infrastructure Resources and should be available, right?