-
Notifications
You must be signed in to change notification settings - Fork 2.4k
feat: Custom domains route53 support #1165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Custom Domains support | ||
|
||
Example SAM template for setting up Api Gateway resources for custom domains. | ||
|
||
## Prerequisites for setting up custom domains | ||
1. A domain name. You can purchase a domain name from a domain name provider. | ||
1. A certificate ARN. Set up or import a valid certificate into AWS Certificate Manager. If the endpoint is EDGE, the certificate must be created in us-east-1. | ||
1. A HostedZone in Route53 for the domain name. | ||
1. A Cloudfront Distribution for the domain if the endpoint is set to EDGE. | ||
|
||
## PostRequisites | ||
After deploying the template, make sure you configure the DNS settings on the domain name provider's website. You will need to add Type A and Type AAAA DNS records that are point to ApiGateway's Hosted Zone Id. Read more [here](https://docs.aws.amazon.com/Route53/latest/DeveloperGuide/routing-to-api-gateway.html) | ||
|
||
## Running the example | ||
|
||
```bash | ||
$ sam deploy \ | ||
--template-file /path_to_template/packaged-template.yaml \ | ||
--stack-name my-new-stack \ | ||
--capabilities CAPABILITY_IAM | ||
``` |
70 changes: 70 additions & 0 deletions
70
examples/2016-10-31/custom_domains_with_route53/template.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
Parameters: | ||
DomainName: | ||
Type: String | ||
Default: 'example.com' | ||
ACMCertificateArn: | ||
Type: String | ||
Default: 'cert-arn-in-us-east-1' | ||
Resources: | ||
MyFunction: | ||
Type: AWS::Serverless::Function | ||
Properties: | ||
InlineCode: | | ||
exports.handler = async (event) => { | ||
const response = { | ||
statusCode: 200, | ||
body: JSON.stringify('Hello from Lambda!'), | ||
}; | ||
return response; | ||
}; | ||
Handler: index.handler | ||
Runtime: nodejs8.10 | ||
Events: | ||
Fetch: | ||
Type: Api | ||
Properties: | ||
RestApiId: !Ref MyApi | ||
Method: Post | ||
Path: /fetch | ||
|
||
MyApi: | ||
Type: AWS::Serverless::Api | ||
Properties: | ||
OpenApiVersion: 3.0.1 | ||
StageName: Prod | ||
Domain: | ||
DomainName: !Ref DomainName | ||
CertificateArn: !Ref ACMCertificateArn | ||
EndpointConfiguration: EDGE | ||
BasePath: | ||
- /fetch | ||
Route53: | ||
HostedZoneId: ZQ1UAL4EFZVME | ||
IpV6: true | ||
DistributionDomainName: !GetAtt Distribution.DomainName | ||
|
||
Distribution: | ||
Type: AWS::CloudFront::Distribution | ||
Properties: | ||
DistributionConfig: | ||
Enabled: true | ||
HttpVersion: http2 | ||
Origins: | ||
- DomainName: !Ref DomainName | ||
Id: !Ref DomainName | ||
CustomOriginConfig: | ||
HTTPPort: 80 | ||
HTTPSPort: 443 | ||
OriginProtocolPolicy: https-only | ||
DefaultCacheBehavior: | ||
AllowedMethods: [ HEAD, DELETE, POST, GET, OPTIONS, PUT, PATCH ] | ||
ForwardedValues: | ||
QueryString: false | ||
SmoothStreaming: false | ||
Compress: true | ||
TargetOriginId: !Ref DomainName | ||
ViewerProtocolPolicy: redirect-to-https | ||
PriceClass: PriceClass_100 | ||
ViewerCertificate: | ||
SslSupportMethod: sni-only | ||
AcmCertificateArn: !Ref ACMCertificateArn |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from samtranslator.model import PropertyType, Resource | ||
from samtranslator.model.types import is_type, is_str | ||
|
||
|
||
class Route53RecordSetGroup(Resource): | ||
resource_type = 'AWS::Route53::RecordSetGroup' | ||
property_types = { | ||
'HostedZoneId': PropertyType(False, is_str()), | ||
'RecordSets': PropertyType(False, is_type(list)), | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
tests/translator/input/api_with_custom_domain_route53.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
Parameters: | ||
DomainName: | ||
Type: String | ||
Default: 'example.com' | ||
ACMCertificateArn: | ||
Type: String | ||
Default: 'cert-arn-in-us-east-1' | ||
Resources: | ||
MyFunction: | ||
Type: AWS::Serverless::Function | ||
Properties: | ||
InlineCode: | | ||
exports.handler = async (event) => { | ||
const response = { | ||
statusCode: 200, | ||
body: JSON.stringify('Hello from Lambda!'), | ||
}; | ||
return response; | ||
}; | ||
Handler: index.handler | ||
Runtime: nodejs8.10 | ||
Events: | ||
Fetch: | ||
Type: Api | ||
Properties: | ||
RestApiId: !Ref MyApi | ||
Method: Post | ||
Path: /fetch | ||
|
||
MyApi: | ||
Type: AWS::Serverless::Api | ||
Properties: | ||
OpenApiVersion: 3.0.1 | ||
StageName: Prod | ||
Domain: | ||
DomainName: !Ref DomainName | ||
CertificateArn: !Ref ACMCertificateArn | ||
EndpointConfiguration: EDGE | ||
BasePath: | ||
- /fetch | ||
Route53: | ||
HostedZoneId: ZQ1UAL4EFZVME | ||
IpV6: true | ||
DistributionDomainName: !GetAtt Distribution.DomainName | ||
|
||
Distribution: | ||
Type: AWS::CloudFront::Distribution | ||
Properties: | ||
DistributionConfig: | ||
Enabled: true | ||
HttpVersion: http2 | ||
Origins: | ||
- DomainName: !Ref DomainName | ||
Id: !Ref DomainName | ||
CustomOriginConfig: | ||
HTTPPort: 80 | ||
HTTPSPort: 443 | ||
OriginProtocolPolicy: https-only | ||
DefaultCacheBehavior: | ||
AllowedMethods: [ HEAD, DELETE, POST, GET, OPTIONS, PUT, PATCH ] | ||
ForwardedValues: | ||
QueryString: false | ||
SmoothStreaming: false | ||
Compress: true | ||
TargetOriginId: !Ref DomainName | ||
ViewerProtocolPolicy: redirect-to-https | ||
PriceClass: PriceClass_100 | ||
ViewerCertificate: | ||
SslSupportMethod: sni-only | ||
AcmCertificateArn: !Ref ACMCertificateArn |
40 changes: 40 additions & 0 deletions
40
tests/translator/input/error_api_with_custom_domains_route53_invalid.yaml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
Resources: | ||
MyFunction: | ||
Type: AWS::Serverless::Function | ||
Properties: | ||
InlineCode: | | ||
exports.handler = async (event) => { | ||
const response = { | ||
statusCode: 200, | ||
body: JSON.stringify('Hello from Lambda!'), | ||
}; | ||
return response; | ||
}; | ||
Handler: index.handler | ||
Runtime: nodejs8.10 | ||
Events: | ||
Api: | ||
Type: Api | ||
Properties: | ||
RestApiId: !Ref MyApi | ||
Method: Put | ||
Path: /get | ||
Fetch: | ||
Type: Api | ||
Properties: | ||
RestApiId: !Ref MyApi | ||
Method: Post | ||
Path: /fetch | ||
|
||
MyApi: | ||
Type: AWS::Serverless::Api | ||
Properties: | ||
OpenApiVersion: 3.0.1 | ||
StageName: Prod | ||
Domain: | ||
DomainName: 'api-example.com' | ||
CertificateArn: 'my-api-cert-arn' | ||
EndpointConfiguration: 'EDGE' | ||
BasePath: [ "/get", "/fetch" ] | ||
Route53: | ||
EvaluateTargetHealth: false |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.