Skip to content

Commit e89a714

Browse files
committed
Merged in upstream/develop
2 parents 3fd4e1f + 7cf48bd commit e89a714

File tree

243 files changed

+9371
-801
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

243 files changed

+9371
-801
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[flake8]
22
max-line-length = 120
3-
ignore = E126
3+
ignore = E126 F821 W504 W605

Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ init:
3939
$(info [*] Install requirements...)
4040
@pip install -r requirements/dev.txt -r requirements/base.txt
4141

42+
flake:
43+
$(info [*] Running flake8...)
44+
@flake8 samtranslator
45+
4246
test:
4347
$(info [*] Run the unit test with minimum code coverage of $(CODE_COVERAGE)%...)
4448
@pytest --cov samtranslator --cov-report term-missing --cov-fail-under $(CODE_COVERAGE) tests
@@ -49,7 +53,7 @@ build-docs:
4953
@$(MAKE) -C docs/website html
5054

5155
# Command to run everytime you make changes to verify everything works
52-
dev: test
56+
dev: flake test
5357

5458
# Verifications to run before sending a pull request
5559
pr: init dev
@@ -68,4 +72,4 @@ TARGETS
6872
build-docs Generate the documentation.
6973
pr Perform all checks before submitting a Pull Request.
7074

71-
endef
75+
endef

README.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[![Build Status](https://travis-ci.org/awslabs/serverless-application-model.svg?branch=develop)](https://travis-ci.org/awslabs/serverless-application-model)
22
[![PyPI version](https://badge.fury.io/py/aws-sam-translator.svg)](https://badge.fury.io/py/aws-sam-translator)
3+
[![Codecov Test Coverage](https://codecov.io/gh/awslabs/serverless-application-model/branch/master/graphs/badge.svg?style=flat)](https://codecov.io/gh/awslabs/serverless-application-model)
34

45
![Logo](aws_sam_introduction.png)
56

@@ -10,16 +11,11 @@ This GitHub project is the starting point for AWS SAM. It contains the SAM speci
1011

1112
The SAM specification and implementation are open sourced under the Apache 2.0 license. The current version of the SAM specification is available at [AWS SAM 2016-10-31](versions/2016-10-31.md).
1213

13-
14-
## Creating a serverless application using SAM
15-
To create a serverless application using SAM, first, you create a SAM template: a JSON or YAML configuration file that describes your Lambda functions, API endpoints and the other resources in your application. Then, you test, upload, and deploy your application using the [AWS SAM CLI](https://github.com/awslabs/aws-sam-cli). During deployment, SAM automatically translates your application’s specification into CloudFormation syntax, filling in default values for any unspecified properties and determining the appropriate mappings and invocation permissions to setup for any Lambda functions.
16-
17-
[Read the How-To Guide](HOWTO.md) and see [examples](examples/) to learn how to define & deploy serverless applications using SAM.
18-
14+
Documentation about using AWS SAM to define, test, and deploy serverless applications is available at [AWS Serverless Application Model Developer Guide](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/what-is-sam.html).
1915

2016
## Contributing new features and enhancements to SAM
2117
You can build serverless applications faster and further simplify your development of serverless applications by defining new event sources, new resource types, and new parameters within SAM. Additionally, you can modify SAM to integrate it with other frameworks and deployment providers from the community for building serverless applications.
2218

2319
[Read the Development Guide](DEVELOPMENT_GUIDE.rst) for in-depth information on how to start making changes.
2420

25-
[Join the SAM developers channel (#samdev) on Slack](https://awssamopensource.splashthat.com/) to collaborate with fellow community members and the AWS SAM team.
21+
[Join the SAM developers channel (#samdev) on Slack](https://join.slack.com/t/awsdevelopers/shared_invite/enQtMzg3NTc5OTM2MzcxLTdjYTdhYWE3OTQyYTU4Njk1ZWY4Y2ZjYjBhMTUxNGYzNDg5MWQ1ZTc5MTRlOGY0OTI4NTdlZTMwNmI5YTgwOGM/) to collaborate with fellow community members and the AWS SAM team.

docs/cloudformation_compatibility.rst

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Tracing All
6060
KmsKeyArn All
6161
DeadLetterQueue All
6262
DeploymentPreference All
63+
Layers All
6364
AutoPublishAlias Ref of a CloudFormation Parameter Alias resources created by SAM uses a LocicalId <FunctionLogicalId+AliasName>. So SAM either needs a string for alias name, or a Ref to template Parameter that SAM can resolve into a string.
6465
ReservedConcurrentExecutions All
6566
============================ ================================== ========================
@@ -168,6 +169,21 @@ EndpointConfiguration All
168169
MethodSettings All
169170
BinaryMediaTypes All
170171
Cors All
172+
TracingEnabled All
173+
================================== ======================== ========================
174+
175+
176+
AWS::Serverless::Application
177+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
178+
179+
================================== ======================== ========================
180+
Property Name Intrinsic(s) Supported Reasons
181+
================================== ======================== ========================
182+
Location None SAM expects exact values for the Location property
183+
Parameters All
184+
NotificationArns All
185+
Tags All
186+
TimeoutInMinutes All
171187
================================== ======================== ========================
172188

173189

docs/conf.py

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3232
# ones.
3333
extensions = ['sphinx.ext.todo',
34-
'sphinx.ext.ifconfig',
35-
'sphinx.ext.viewcode',
36-
'sphinx.ext.githubpages']
34+
'sphinx.ext.ifconfig',
35+
'sphinx.ext.viewcode',
36+
'sphinx.ext.githubpages']
3737

3838
# Add any paths that contain templates here, relative to this directory.
3939
templates_path = ['_templates']
@@ -85,25 +85,29 @@
8585
# The theme to use for HTML and HTML Help pages. See the documentation for
8686
# a list of builtin themes.
8787
#
88-
html_theme = 'alabaster'
88+
html_theme = 'sphinx_rtd_theme'
8989

9090
# Theme options are theme-specific and customize the look and feel of a theme
9191
# further. For a list of options available for each theme, see the
9292
# documentation.
9393
#
94+
9495
html_theme_options = {
95-
'description': "Define your serverless infrastructure as a simple YAML file",
96-
'logo': 'logo.png',
97-
'logo_name': True,
98-
'logo_text_align': 'center',
99-
'github_user': 'awslabs',
100-
'github_repo': 'serverless-application-model',
101-
'github_button': True,
102-
'github_type': 'star',
103-
'github_banner': True,
104-
'sidebar_collapse': True,
10596
}
10697

98+
# html_theme_options = {
99+
# 'description': "Define your serverless infrastructure as a simple YAML file",
100+
# 'logo': 'logo.png',
101+
# 'logo_name': True,
102+
# 'logo_text_align': 'center',
103+
# 'github_user': 'awslabs',
104+
# 'github_repo': 'serverless-application-model',
105+
# 'github_button': True,
106+
# 'github_type': 'star',
107+
# 'github_banner': True,
108+
# 'sidebar_collapse': True,
109+
# }
110+
107111
# Add any paths that contain custom static files (such as style sheets) here,
108112
# relative to this directory. They are copied after the builtin static files,
109113
# so a file named "default.css" will overwrite the builtin "default.css".
@@ -116,9 +120,9 @@
116120
# refs: http://alabaster.readthedocs.io/en/latest/installation.html#sidebars
117121
html_sidebars = {
118122
'**': [
119-
'about.html',
120-
'navigation.html',
121-
'relations.html'
123+
'about.html',
124+
'navigation.html',
125+
'relations.html'
122126
]
123127
}
124128

@@ -180,7 +184,6 @@
180184
]
181185

182186

183-
184187
# -- Options for Epub output ----------------------------------------------
185188

186189
# Bibliographic Dublin Core info.
@@ -200,5 +203,3 @@
200203

201204
# A list of files that should not be packed into the epub file.
202205
epub_exclude_files = ['search.html']
203-
204-

docs/globals.rst

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ Example:
2323
Resources:
2424
HelloWorldFunction:
2525
Type: AWS::Serverless::Function
26-
Environment:
27-
Variables:
28-
MESSAGE: "Hello From SAM"
26+
Properties:
27+
Environment:
28+
Variables:
29+
MESSAGE: "Hello From SAM"
2930
3031
ThumbnailFunction:
3132
Type: AWS::Serverless::Function
@@ -64,6 +65,7 @@ Currently, the following resources and properties are being supported:
6465
Tags:
6566
Tracing:
6667
KmsKeyArn:
68+
Layers:
6769
AutoPublishAlias:
6870
DeploymentPreference:
6971
@@ -79,6 +81,9 @@ Currently, the following resources and properties are being supported:
7981
MethodSettings:
8082
BinaryMediaTypes:
8183
Cors:
84+
AccessLogSetting:
85+
CanarySetting:
86+
TracingEnabled:
8287
8388
SimpleTable:
8489
# Properties of AWS::Serverless::SimpleTable

docs/internals/generated_resources.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Example:
7070
AutoPublishAlias: live
7171
DeploymentPreference:
7272
Type: Linear10PercentEvery10Minutes
73+
Role: "arn"
7374
...
7475
7576
@@ -83,6 +84,8 @@ AWS::CodeDeploy::DeploymentGroup MyFunction\ **DeploymentGroup**
8384
AWS::IAM::Role CodeDeployServiceRole
8485
================================== ================================
8586

87+
NOTE: ``AWS::IAM::Role`` resources are only generated if no Role parameter is supplied for DeploymentPreference
88+
8689
With Events
8790
~~~~~~~~~~~
8891

docs/safe_lambda_deployments.rst

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ resource:
105105
# Validation Lambda functions that are run before & after traffic shifting
106106
PreTraffic: !Ref PreTrafficLambdaFunction
107107
PostTraffic: !Ref PostTrafficLambdaFunction
108+
# Provide a custom role for CodeDeploy traffic shifting here, if you don't supply one
109+
# SAM will create one for you with default permissions
110+
Role: !Ref IAMRoleForCodeDeploy # Parameter example, you can pass an IAM ARN
108111
109112
AliasErrorMetricGreaterThanZeroAlarm:
110113
Type: "AWS::CloudWatch::Alarm"
@@ -130,9 +133,11 @@ resource:
130133
ComparisonOperator: GreaterThanThreshold
131134
Dimensions:
132135
- Name: Resource
133-
Value: !Ref MyLambdaFunction.Version
136+
Value: !Sub "${MyLambdaFunction}:live"
134137
- Name: FunctionName
135138
Value: !Ref MyLambdaFunction
139+
- Name: ExecutedVersion
140+
Value: !GetAtt MyLambdaFunction.Version.Version
136141
EvaluationPeriods: 2
137142
MetricName: Errors
138143
Namespace: AWS/Lambda
@@ -162,6 +167,7 @@ resource:
162167
FunctionName: 'CodeDeployHook_preTrafficHook'
163168
DeploymentPreference:
164169
Enabled: false
170+
Role: ""
165171
Environment:
166172
Variables:
167173
CurrentVersion: !Ref MyLambdaFunction.Version
@@ -176,6 +182,7 @@ CloudFormation, the following happens:
176182
- During traffic shifting, if any of the CloudWatch Alarms go to *Alarm* state, CodeDeploy will immediately flip the Alias back to old version and report a failure to CloudFormation.
177183
- After traffic shifting completes, CodeDeploy will invoke the **PostTraffic Hook** Lambda function. This is similar to PreTraffic Hook where the function must callback to CodeDeploy to report a Success or a Failure. PostTraffic hook is a great place to run integration tests or other validation actions.
178184
- If everything went well, the Alias will be pointing to the new Lambda Version.
185+
- If you supply the "Role" argument to the DeploymentPreference, it will prevent SAM from creating a role and instead use the provided CodeDeploy role for traffic shifting
179186

180187
NOTE: Verify that your AWS SDK version supports PutLifecycleEventHookExecutionStatus. For example, Python requires SDK version 1.4.8 or newer.
181188

@@ -294,13 +301,32 @@ Internally, SAM will create the following resources in your CloudFormation stack
294301
SAM template belongs to its own Deployment Group.
295302
- Adds ``UpdatePolicy`` on ``AWS::Lambda::Alias`` resource that is
296303
connected to the function's Deployment Group resource.
297-
- One ``AWS::IAM::Role`` called "CodeDeployServiceRole".
304+
- One ``AWS::IAM::Role`` called "CodeDeployServiceRole", if no custom role is provided
298305

299306
CodeDeploy assumes that there are no dependencies between Deployment Groups and hence will deploy them in parallel.
300307
Since every Lambda function is to its own CodeDeploy DeploymentGroup, they will be deployed in parallel.
301308
The CodeDeploy service will assume the new CodeDeployServiceRole to Invoke any Pre/Post hook functions and perform the traffic shifting and Alias updates.
302309

303310
NOTE: The CodeDeployServiceRole only allows InvokeFunction on functions with names prefixed with ``CodeDeployHook_``. For example, you should name your Hook functions as such: ``CodeDeployHook_PreTrafficHook``.
304311

312+
Production errors preventing deployments
313+
~~~~~~~~~
314+
In some situations, an issue that is happening in production may prevent you from deploying a fix. This may happen when a deployment happens when traffic is too low to register enough errors to trigger a roll back, or where someone is sending malicious traffic through to a lambda and you haven’t accounted for the scenario where they do.
315+
316+
When this happens, the alarm for errors in the current lambda version is in an error state, which will cause code deploy to roll back any attempted deploys straight away.
317+
318+
To release code in this situation, you need to
319+
320+
- Go into the CodeDeploy console
321+
- Select the application you want to deploy to
322+
- Select the corresponding Deployment Group
323+
- Select “Edit”
324+
- Select “Advanced - optional”
325+
- Select "ignore alarm configuration"
326+
- Save the changes
327+
328+
Run your deployment as usual
329+
330+
Then once deployment has successfully run, return to the CodeDeploy console, and follow the above steps but this time deselect “ignore alarm configuration”.
305331

306332
.. _Globals: globals.rst

examples/2016-10-31/api_backend/template.yaml

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
AWSTemplateFormatVersion: '2010-09-09'
1+
AWSTemplateFormatVersion: "2010-09-09"
22
Transform: AWS::Serverless-2016-10-31
33
Description: Simple CRUD webservice. State is stored in a SimpleTable (DynamoDB) resource.
44
Resources:
@@ -8,7 +8,9 @@ Resources:
88
Handler: index.get
99
Runtime: nodejs6.10
1010
CodeUri: src/
11-
Policies: AmazonDynamoDBReadOnlyAccess
11+
Policies:
12+
- DynamoDBReadPolicy:
13+
TableName: !Ref Table
1214
Environment:
1315
Variables:
1416
TABLE_NAME: !Ref Table
@@ -25,7 +27,9 @@ Resources:
2527
Handler: index.put
2628
Runtime: nodejs6.10
2729
CodeUri: src/
28-
Policies: AmazonDynamoDBFullAccess
30+
Policies:
31+
- DynamoDBCrudPolicy:
32+
TableName: !Ref Table
2933
Environment:
3034
Variables:
3135
TABLE_NAME: !Ref Table
@@ -42,7 +46,9 @@ Resources:
4246
Handler: index.delete
4347
Runtime: nodejs6.10
4448
CodeUri: src/
45-
Policies: AmazonDynamoDBFullAccess
49+
Policies:
50+
- DynamoDBCrudPolicy:
51+
TableName: !Ref Table
4652
Environment:
4753
Variables:
4854
TABLE_NAME: !Ref Table
@@ -57,7 +63,6 @@ Resources:
5763
Type: AWS::Serverless::SimpleTable
5864

5965
Outputs:
60-
ApiURL:
61-
Description: "API endpoint URL for Prod environment"
62-
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/resource/"
63-
66+
ApiURL:
67+
Description: "API endpoint URL for Prod environment"
68+
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/resource/"

examples/2016-10-31/api_cognito_auth/template.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Resources:
4040
RestApiId: !Ref MyApi
4141
Path: /
4242
Method: GET
43+
# NOTE: This endpoint is publicly accessible
4344
Auth:
4445
Authorizer: NONE
4546
ProxyAny:
@@ -48,6 +49,7 @@ Resources:
4849
RestApiId: !Ref MyApi
4950
Path: /{proxy+}
5051
Method: ANY
52+
# NOTE: This endpoint is publicly accessible
5153
Auth:
5254
Authorizer: NONE
5355
GetUsers:
@@ -56,6 +58,7 @@ Resources:
5658
RestApiId: !Ref MyApi
5759
Path: /users
5860
Method: GET
61+
# NOTE: This endpoint is publicly accessible
5962
Auth:
6063
Authorizer: NONE
6164
GetUser:
@@ -64,6 +67,7 @@ Resources:
6467
RestApiId: !Ref MyApi
6568
Path: /users/{userId}
6669
Method: GET
70+
# NOTE: This endpoint is publicly accessible
6771
Auth:
6872
Authorizer: NONE
6973
CreateUser:

0 commit comments

Comments
 (0)