-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* API * CORS * Regional endpoints * Binary media types * Logging, Metrics & CacheTTL (MethodSettings) * Function * Per-Function Concurrency (ReservedConcurrentExecutions) * SimpleTable: * Tags * TableName * Refer to resources generated by API: * `!Ref MyApi.Stage` => Ref the Stage generated by SAM * `!Ref MyApi.Deployment` => Ref the Deployment resource generated by SAM
- Loading branch information
Showing
7 changed files
with
220 additions
and
72 deletions.
There are no files selected for viewing
This file contains 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 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 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 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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,90 @@ | ||
--- | ||
Transform: AWS::Serverless-2016-10-31 | ||
|
||
Globals: | ||
Api: | ||
# Allows www.example.com to call these APIs | ||
# SAM will automatically add AllowMethods with a list of methods for this API | ||
Cors: "'https://www.www.example.com'" | ||
|
||
# API Gateway regional endpoints | ||
EndpointConfiguration: REGIONAL | ||
|
||
# Send/receive binary data through the APIs | ||
BinaryMediaTypes: | ||
# This is equivalent to image/gif when deployed | ||
- image~1gif | ||
- iimage~1png | ||
|
||
# Logging, Metrics, Throttling, and all other Stage settings | ||
MethodSettings: [{ | ||
# Turn on Info logging | ||
"LoggingLevel": "INFO", | ||
|
||
# Enable Metrics | ||
"MetricsEnabled": True, | ||
|
||
# Trace-level Logging | ||
"DataTraceEnabled": True, | ||
|
||
# On all Paths & methods | ||
"ResourcePath": "/*", | ||
"HttpMethod": "*", | ||
}] | ||
|
||
Resources: | ||
LambdaFunction: | ||
Type: AWS::Serverless::Function | ||
Properties: | ||
# Replace <bucket> with your bucket name | ||
CodeUri: s3://<bucket>/code.zip | ||
Handler: index.handler | ||
Runtime: nodejs6.10 | ||
Events: | ||
ProxyApiRoot: | ||
Type: Api | ||
Properties: | ||
Path: / | ||
Method: ANY | ||
ProxyApiGreedy: | ||
Type: Api | ||
Properties: | ||
Path: /{proxy+} | ||
Method: ANY | ||
|
||
####### Necessary for API Gateway Logging ######## | ||
# Add the CloudWatchRole and Account resource to your template to give API Gateway permissions write to CloudWatch logs | ||
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-account.html#aws-resource-apigateway-account-examples | ||
# | ||
# NOTE: This is a one time process. As long as you have this enabled once in a region, you can deploy other stacks | ||
# without the need for each stack to create this role. As a good practice, create a separate stack altogether | ||
# with just the API Gateway logging role so none of your application stacks need them. | ||
ApiGwAccountConfig: | ||
Type: "AWS::ApiGateway::Account" | ||
Properties: | ||
CloudWatchRoleArn: !GetAtt "ApiGatewayLoggingRole.Arn" | ||
ApiGatewayLoggingRole: | ||
Type: "AWS::IAM::Role" | ||
Properties: | ||
AssumeRolePolicyDocument: | ||
Version: "2012-10-17" | ||
Statement: | ||
- Effect: Allow | ||
Principal: | ||
Service: | ||
- "apigateway.amazonaws.com" | ||
Action: "sts:AssumeRole" | ||
Path: "/" | ||
ManagedPolicyArns: | ||
- !Sub "arn:${AWS::Partition}:iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs" | ||
|
||
Outputs: | ||
ApiUrl: | ||
Description: URL of your API endpoint | ||
Value: !Join | ||
- '' | ||
- - https:// | ||
- !Ref ServerlessRestApi | ||
- '.execute-api.' | ||
- !Ref 'AWS::Region' | ||
- '.amazonaws.com/Prod' |
Oops, something went wrong.