-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Adds support for HostedZoneName instead of HostedZoneId in Domain section of the Api #1408
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 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7d0c87f
Adds support for HostedZoneName instead of HostedZoneId in Domain sec…
mbarneyjr f7298dd
Updates documentation, adds example for hosted zone name support
mbarneyjr b18fe73
Update samtranslator/model/api/api_generator.py
mbarneyjr 255284e
adds tests, fixes missing piece in logicalID generator
mbarneyjr e018454
Merge branch 'feature/hosted-zone-name' of github.com:mbarneyjr/serve…
mbarneyjr b161f59
Merge branch 'develop' into feature/hosted-zone-name
keetonian 23b4c64
ran make black
mbarneyjr 676c574
Merge branch 'feature/hosted-zone-name' of github.com:mbarneyjr/serve…
mbarneyjr a975312
Fixed broken test
mbarneyjr 71d3112
Fix failing tests
keetonian 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
22 changes: 22 additions & 0 deletions
22
examples/2016-10-31/custom_domains_with_route53_hosted_zone_name/README.md
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,22 @@ | ||
# 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. | ||
|
||
## 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 | ||
``` | ||
|
||
Curl to the endpoint "http://example.com/home/fetch" should hit the Api. |
71 changes: 71 additions & 0 deletions
71
examples/2016-10-31/custom_domains_with_route53_hosted_zone_name/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,71 @@ | ||
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: | ||
- /home | ||
Route53: | ||
HostedZoneName: www.my-domain.com. | ||
IpV6: true | ||
## ====== Everything below here is optional, leave this out if you want to use the internal Api Gateway distribution ======= | ||
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
43 changes: 43 additions & 0 deletions
43
tests/translator/input/api_with_custom_domain_route53_hosted_zone_name.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,43 @@ | ||
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: nodejs12.x | ||
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: | ||
- /one | ||
Route53: | ||
HostedZoneName: www.my-domain.com. | ||
IpV6: true |
197 changes: 197 additions & 0 deletions
197
tests/translator/output/api_with_custom_domain_route53_hosted_zone_name.json
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,197 @@ | ||
{ | ||
"Parameters": { | ||
"ACMCertificateArn": { | ||
"Default": "cert-arn-in-us-east-1", | ||
"Type": "String" | ||
}, | ||
"DomainName": { | ||
"Default": "example.com", | ||
"Type": "String" | ||
} | ||
}, | ||
"Resources": { | ||
"MyFunction": { | ||
"Type": "AWS::Lambda::Function", | ||
"Properties": { | ||
"Handler": "index.handler", | ||
"Code": { | ||
"ZipFile": "exports.handler = async (event) => {\n const response = {\n statusCode: 200,\n body: JSON.stringify('Hello from Lambda!'),\n };\n return response;\n};\n" | ||
}, | ||
"Role": { | ||
"Fn::GetAtt": [ | ||
"MyFunctionRole", | ||
"Arn" | ||
] | ||
}, | ||
"Runtime": "nodejs12.x", | ||
"Tags": [ | ||
{ | ||
"Value": "SAM", | ||
"Key": "lambda:createdBy" | ||
} | ||
] | ||
} | ||
}, | ||
"MyFunctionFetchPermissionProd": { | ||
"Type": "AWS::Lambda::Permission", | ||
"Properties": { | ||
"Action": "lambda:InvokeFunction", | ||
"Principal": "apigateway.amazonaws.com", | ||
"FunctionName": { | ||
"Ref": "MyFunction" | ||
}, | ||
"SourceArn": { | ||
"Fn::Sub": [ | ||
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/POST/fetch", | ||
{ | ||
"__Stage__": "*", | ||
"__ApiId__": { | ||
"Ref": "MyApi" | ||
} | ||
} | ||
] | ||
} | ||
} | ||
}, | ||
"ApiGatewayDomainName0caaf24ab1": { | ||
"Type": "AWS::ApiGateway::DomainName", | ||
"Properties": { | ||
"CertificateArn": "cert-arn-in-us-east-1", | ||
"EndpointConfiguration": { | ||
"Types": [ | ||
"EDGE" | ||
] | ||
}, | ||
"DomainName": "example.com" | ||
} | ||
}, | ||
"RecordSetGroup456ebaf280": { | ||
"Type": "AWS::Route53::RecordSetGroup", | ||
"Properties": { | ||
"HostedZoneName": "www.my-domain.com.", | ||
"RecordSets": [ | ||
{ | ||
"AliasTarget": { | ||
"HostedZoneId": "Z2FDTNDATAQYW2", | ||
"DNSName": { | ||
"Fn::GetAtt": [ | ||
"ApiGatewayDomainName0caaf24ab1", | ||
"DistributionDomainName" | ||
] | ||
} | ||
}, | ||
"Type": "A", | ||
"Name": "example.com" | ||
}, | ||
{ | ||
"AliasTarget": { | ||
"HostedZoneId": "Z2FDTNDATAQYW2", | ||
"DNSName": { | ||
"Fn::GetAtt": [ | ||
"ApiGatewayDomainName0caaf24ab1", | ||
"DistributionDomainName" | ||
] | ||
} | ||
}, | ||
"Type": "AAAA", | ||
"Name": "example.com" | ||
} | ||
] | ||
} | ||
}, | ||
"MyApiDeploymentf643ef7f59": { | ||
"Type": "AWS::ApiGateway::Deployment", | ||
"Properties": { | ||
"RestApiId": { | ||
"Ref": "MyApi" | ||
}, | ||
"Description": "RestApi deployment id: f643ef7f592a69a57638dd25e64dc12d2b4abf2d" | ||
} | ||
}, | ||
"MyApioneBasePathMapping": { | ||
"Type": "AWS::ApiGateway::BasePathMapping", | ||
"Properties": { | ||
"BasePath": "one", | ||
"DomainName": { | ||
"Ref": "ApiGatewayDomainName0caaf24ab1" | ||
}, | ||
"RestApiId": { | ||
"Ref": "MyApi" | ||
}, | ||
"Stage": { | ||
"Ref": "MyApiProdStage" | ||
} | ||
} | ||
}, | ||
"MyApiProdStage": { | ||
"Type": "AWS::ApiGateway::Stage", | ||
"Properties": { | ||
"DeploymentId": { | ||
"Ref": "MyApiDeploymentf643ef7f59" | ||
}, | ||
"RestApiId": { | ||
"Ref": "MyApi" | ||
}, | ||
"StageName": "Prod" | ||
} | ||
}, | ||
"MyFunctionRole": { | ||
"Type": "AWS::IAM::Role", | ||
"Properties": { | ||
"AssumeRolePolicyDocument": { | ||
"Version": "2012-10-17", | ||
"Statement": [ | ||
{ | ||
"Action": [ | ||
"sts:AssumeRole" | ||
], | ||
"Effect": "Allow", | ||
"Principal": { | ||
"Service": [ | ||
"lambda.amazonaws.com" | ||
] | ||
} | ||
} | ||
] | ||
}, | ||
"ManagedPolicyArns": [ | ||
"arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" | ||
], | ||
"Tags": [ | ||
{ | ||
"Value": "SAM", | ||
"Key": "lambda:createdBy" | ||
} | ||
] | ||
} | ||
}, | ||
"MyApi": { | ||
"Type": "AWS::ApiGateway::RestApi", | ||
"Properties": { | ||
"Body": { | ||
"info": { | ||
"version": "1.0", | ||
"title": { | ||
"Ref": "AWS::StackName" | ||
} | ||
}, | ||
"paths": { | ||
"/fetch": { | ||
"post": { | ||
"x-amazon-apigateway-integration": { | ||
"httpMethod": "POST", | ||
"type": "aws_proxy", | ||
"uri": { | ||
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyFunction.Arn}/invocations" | ||
} | ||
}, | ||
"responses": {} | ||
} | ||
} | ||
}, | ||
"openapi": "3.0.1" | ||
} | ||
} | ||
} | ||
} | ||
} |
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.