Comments (15)
For me this works:
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Description: subsidy_request_mailer
Parameters:
DomainName:
Type: String
Default: api.example.com
HostedZoneName:
Type: String
Default: example.com. # don't miss the dot at the end
Resources:
SendFunction:
Type: AWS::Serverless::Function
Properties:
CodeUri: send/
Handler: app.lambda_handler
Runtime: nodejs8.10
Events:
send:
Type: Api
Properties:
Path: /send
Method: get
APIDomainName:
Type: AWS::ApiGateway::DomainName
Properties:
CertificateArn: arn:aws:acm:us-east-1:...:certificate/...
DomainName: !Ref DomainName
APIBasePathMapping:
Type: AWS::ApiGateway::BasePathMapping
Properties:
DomainName: !Ref APIDomainName
RestApiId: !Ref ServerlessRestApi
Stage: Prod
APIDomain:
Type: AWS::Route53::RecordSetGroup
Properties:
HostedZoneName: !Ref HostedZoneName
RecordSets:
- Name: !Ref DomainName
Type: A
AliasTarget:
DNSName: !GetAtt APIDomainName.DistributionDomainName
HostedZoneId: Z2FDTNDATAQYW2 # static ID for CloudFront aliases
from serverless-application-model.
@whereisaaron thanks for the feedback. I think it will be really valuable to add this example to the examples folder. Reopening this issue.
from serverless-application-model.
I tried @timoschilling snippet, but I get Cannot import certificates for REGIONAL while EDGE is active
and I cannot find anything on the internet with this error message.
from serverless-application-model.
The solution is to set
EndpointConfiguration:
Types:
- REGIONAL
from serverless-application-model.
Solid example @timoschilling -- saved me a TON of time.
from serverless-application-model.
@praneetap can we close this issue now with #1144 merged?
from serverless-application-model.
I am afraid not.. AFAIK CloudFormation hasn't supported APIGW custom domains yet. So SAM does not
from serverless-application-model.
@sanathkr thanks for the info. I'll just close this for the time being, then.
from serverless-application-model.
@frehner any update on this ?
from serverless-application-model.
Iām not working on this at all. You will want to ask one of the maintainers
from serverless-application-model.
@frehner thanks, sorry for the confusion.
@sanathkr any update on the ability to define a custom domain name in SAM or CloudFormation ?
from serverless-application-model.
RFC for Custom Domain Names #783
from serverless-application-model.
Good question. Please any AWS Guru ?
from serverless-application-model.
@timoschilling +1 saved me a tonne of time. Is there an example similar to this in the docs anywhere or would it be worth putting in a PR?
from serverless-application-model.
@timoschilling your example was the best example I could find all all of the interwebs. I was amazed that your example works. I am sure it saved me a ton of time over working out a workaround for SAM myself. AWS should definitely grab this into the documentation.
The documentation SAM, API Gateway, and github issues, none of them had working examples, just obfuscated discussions about SAM not supporting custom domains, and obscure stuff about EDGE or REGIONAL (behind manual CloudFront). I was amazed SAM didn't have support for custom domains out of the box. Made me wonder if I shouldn't switch from SAM to Serverless!
Some notes to help others who might want to following the same example:
(1) One key point is that the !Ref ServerlessRestApi
in @timoschilling's example works because the AWS::Serverless-2016-10-31
transform creates a AWS::ApiGateway::RestApi
resource that happens to have that name. That's a pretty brittle assumption, so if you have trouble, check the resources generated by the stack that it still has that name.
(2) Second, there is a tiny bug in @timoschilling's example, where is says:
HostedZoneName:
Type: String
Default: example.com
The zone name has to be a rooted zone name ending in a '.', e.g. example.com.
Otherwise CloudFront will not find the domain.
(2) The CertificateArn:
needs to be a us-east-1
certificate regardless of where you are deploying the stack. CloudFront gets all it certs from us-east-1
. You might be able to use a regional cert if you switch to a REGIONAL
as @deleugpn suggests but I haven't tested that myself.
from serverless-application-model.
Related Issues (20)
- `AWS::Serverless::Api` creates stage named `Stage` instead of requested stage name HOT 6
- "Invalid OpenAPI input" when OpenAPI set to `3.1.0` HOT 4
- AWS SAM Connector Write needs PutObjectTagging HOT 2
- Setting the runtime of a function to nodejs20.x causes sam validate to fail. HOT 2
- AWS::Serverless::Api - setting "OpenApiVersion" causes "Stage" deployment to be skipped - why? HOT 6
- [Test] GitHub Action automatic comments on GitHub closed Issue HOT 1
- AlwaysDeploy does not include GatewayResponse updates HOT 7
- Please explain how to version AWS::Serverless::Function artifacts cleanly HOT 11
- Bug: AWS::Serverless::Function Policies partly not applied HOT 8
- Cors error from SAM template and Auth enabled. HOT 3
- VSCode SAM Schema Validation Error with !Ref in Conditions Section HOT 7
- Bug: Creates unnecessary AWSLambdaVPCAccessExecutionRole role HOT 7
- Api CORS issue with 500 status after setup Cognito authorizer HOT 3
- Building features for AWS SAM HOT 4
- Can't reset BinaryMediaTypes to a default value for API Gateway REST API HOT 2
- AWS::Serverless::Api auto deploys API when a resource is being added HOT 4
- Environment variables not updated HOT 5
- Bug: Using a Ref in StageName is Not Working Properly - Template.yaml HOT 4
- !If not working on Serverless:Function handler HOT 5
- how to configure KMSVerifyPolicy and KMSSignPolicy HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
š Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ššš
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ā¤ļø Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from serverless-application-model.