Skip to content

Commit 5adc4ef

Browse files
authored
chore: merge pull request aws#593 from awslabs/release/v1.7.0
Release/v1.7.0
2 parents e8f74f5 + c487006 commit 5adc4ef

File tree

162 files changed

+2789
-3584
lines changed

Some content is hidden

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

162 files changed

+2789
-3584
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Here are some questions that you should answer in your plan:
5959

6060
- **How do developers work around this problem today?**
6161

62-
Example: Manually click through every step on the website while refering to
62+
Example: Manually click through every step on the website while referring to
6363
"How To" resources on the internet.
6464

6565
- **Describe your proposed solution?**

HOWTO.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
# How to create serverless applications using AWS SAM
2-
AWS Serverless Application Model (AWS SAM) allows you to easily create and
2+
The AWS Serverless Application Model (AWS SAM) allows you to easily create and
33
manage resources used in your serverless application using AWS CloudFormation.
44
You can define your serverless application as a SAM template - a JSON or YAML
55
configuration file that describes Lambda function, API endpoints and
6-
other resources in your application. Using nifty commands, you upload this
7-
template to CloudFormation which creates all the individual resources and
6+
other resources in your application. Using a variety of [nifty commands](https://github.com/awslabs/aws-sam-cli#usage), you upload this
7+
template to CloudFormation, which in turn creates all the individual resources and
88
groups them into a *CloudFormation Stack* for ease of management.
99
When you update your SAM template, you will re-deploy the changes to
1010
this stack. AWS CloudFormation will take care of updating the individual
1111
resources for you.
1212

1313

14-
The remainder of document explains how to write SAM templates and
14+
The remainder of this document explains how to write SAM templates and
1515
deploy them via AWS CloudFormation.
1616

1717
## Writing SAM Template
18-
Checkout the [latest specification](versions/2016-10-31.md) for details on how to write a SAM template
18+
Check out the [latest specification](versions/2016-10-31.md) for details on how to write a SAM template
1919

2020
## Packing Artifacts
2121
Before you can deploy a SAM template, you should first upload your Lambda
@@ -71,7 +71,7 @@ SAM template is deployed to AWS CloudFormation by [creating a changeset](http://
7171
using the SAM template followed by [executing the changeset](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-changesets-execute.html).
7272
Think of a ChangeSet as a diff between your current stack template and the new template that you are deploying. After you create a ChangeSet, you have the opportunity to examine the diff before executing it. Both the AWS Console and AWS CLI provide commands to create and execute a changeset.
7373

74-
Alternatively, you can use `aws cloudformation deploy` CLI command to deploy the SAM template. Under-the-hood it creates and executes a changeset and waits until the deployment completes. It also prints debugging hints when the deployment fails. Run the following command to deploy the packaged template to a stack called `my-new-stack`:
74+
Alternatively, you can use `aws cloudformation deploy` CLI command to deploy the SAM template. Under the hood it creates and executes a changeset and waits until the deployment completes. It also prints debugging hints when the deployment fails. Run the following command to deploy the packaged template to a stack called `my-new-stack`:
7575

7676
```bash
7777
$ aws cloudformation deploy \
@@ -83,7 +83,7 @@ $ aws cloudformation deploy \
8383
Refer to the [documentation](http://docs.aws.amazon.com/cli/latest/reference/cloudformation/deploy/index.html) for more details.
8484

8585
## Using Intrinsic Functions
86-
CloudFormation provides handy functions you can use to generate values at runtime. These are called [Intrinsic Functions](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html). Since SAM is deployed using CloudFormation, you can use these intrinsic functions within SAM as well. Here are some examples:
86+
CloudFormation provides handy functions that you can use to generate values at runtime. These are called [Intrinsic Functions](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference.html). Since SAM is deployed using CloudFormation, you can use these intrinsic functions within SAM as well. Here are some examples:
8787

8888
#### Dynamically set S3 location of Lambda function code zip
8989
```YAML
@@ -136,7 +136,7 @@ Resources:
136136
137137
### Caveats:
138138
#### ImportValue is partially supported
139-
[`ImportValue`](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-importvalue.html) allows one stack to refer to value of properties from another stack. ImportValue is supported on most properties, except the very few that SAM needs to parse. Following properties are *not* supported:
139+
[`ImportValue`](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-importvalue.html) allows one stack to refer to the value of properties from another stack. ImportValue is supported on most properties, except the very few that SAM needs to parse. The following properties are *not* supported:
140140

141141
- `RestApiId` of `AWS::Serverless::Function`
142142
- `Policies` of `AWS::Serverless::Function`

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ The SAM specification and implementation are open sourced under the Apache 2.0 l
1212

1313

1414
## 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 [SAM Local CLI](https://github.com/awslabs/aws-sam-local). 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.
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.
1616

1717
[Read the How-To Guide](HOWTO.md) and see [examples](examples/) to learn how to define & deploy serverless applications using SAM.
1818

bin/sam-translate.py

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
from samtranslator.public.translator import ManagedPolicyLoader
2222
from samtranslator.translator.transform import transform
2323
from samtranslator.yaml_helper import yaml_parse
24+
from samtranslator.model.exceptions import InvalidDocumentException
25+
2426

2527
cli_options = docopt(__doc__)
2628
iam_client = boto3.client('iam')
@@ -42,15 +44,21 @@ def main():
4244
with open(input_file_path, 'r') as f:
4345
sam_template = yaml_parse(f)
4446

45-
cloud_formation_template = transform(
46-
sam_template, {}, ManagedPolicyLoader(iam_client))
47-
cloud_formation_template_prettified = json.dumps(
48-
cloud_formation_template, indent=2)
49-
50-
with open(output_file_path, 'w') as f:
51-
f.write(cloud_formation_template_prettified)
52-
53-
print('Wrote transformed CloudFormation template to: ' + output_file_path)
47+
try:
48+
cloud_formation_template = transform(
49+
sam_template, {}, ManagedPolicyLoader(iam_client))
50+
cloud_formation_template_prettified = json.dumps(
51+
cloud_formation_template, indent=2)
52+
53+
with open(output_file_path, 'w') as f:
54+
f.write(cloud_formation_template_prettified)
55+
56+
print('Wrote transformed CloudFormation template to: ' + output_file_path)
57+
except InvalidDocumentException as e:
58+
errorMessage = reduce(lambda message, error: message + ' ' + error.message, e.causes, e.message)
59+
print(errorMessage)
60+
errors = map(lambda cause: {'errorMessage': cause.message}, e.causes)
61+
print(errors)
5462

5563

5664
if __name__ == '__main__':

docs/globals.rst

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,19 @@ In the above example, both ``HelloWorldFunction`` and ``ThumbnailFunction`` will
4242
timeout and index.handler Handler. ``HelloWorldFunction`` adds MESSAGE environment variable in addition to the
4343
inherited TABLE_NAME. ``ThumbnailFunction`` inherits all the Globals properties and adds an API Event source.
4444

45-
Supported Resources
46-
-------------------
47-
Properties of ``AWS::Serverless::Function`` and ``AWS::Serverless::Api`` are only supported in Globals section
48-
presently.
45+
Supported Resources and Properties
46+
----------------------------------
47+
Currently, the following resources and properties are being supported:
4948

5049
.. code:: yaml
5150
5251
Globals:
5352
Function:
54-
# Some properties of AWS::Serverless::Function
53+
# Properties of AWS::Serverless::Function
5554
Handler:
5655
Runtime:
57-
CodeUri:
56+
# Specifying CodeUri on Globals is not yet supported by 'CloudFormation package' https://docs.aws.amazon.com/cli/latest/reference/cloudformation/package.html
57+
CodeUri:
5858
DeadLetterQueue:
5959
Description:
6060
MemorySize:
@@ -68,7 +68,7 @@ presently.
6868
DeploymentPreference:
6969
7070
Api:
71-
# Some properties of AWS::Serverless::Api
71+
# Properties of AWS::Serverless::Api
7272
# Also works with Implicit APIs
7373
Name:
7474
DefinitionUri:
@@ -81,6 +81,7 @@ presently.
8181
Cors:
8282
8383
SimpleTable:
84+
# Properties of AWS::Serverless::SimpleTable
8485
SSESpecification
8586
8687
Implicit APIs
@@ -143,20 +144,19 @@ Runtime of ``MyFunction`` will be set to python3.6
143144
144145
Maps are merged
145146
~~~~~~~~~~~~~~~
146-
*Also called as dictionaries, or key/value pairs*
147+
*Maps are also known as dictionaries or collections of key/value pairs*
147148

148-
Map value in the resource will be **merged** with the map value from Global.
149+
Map entries in the resource will be **merged** with global map entries. In case of duplicates the resource entry will override the global entry.
149150

150151
Example:
151152

152-
Environment variables of ``MyFunction`` will be set to ``{ TABLE_NAME: "resource-table", "NEW_VAR": "hello" }``
153-
154153
.. code:: yaml
155154
156155
Globals:
157156
Function:
158157
Environment:
159158
Variables:
159+
STAGE: Production
160160
TABLE_NAME: global-table
161161
162162
Resources:
@@ -168,16 +168,24 @@ Environment variables of ``MyFunction`` will be set to ``{ TABLE_NAME: "resource
168168
TABLE_NAME: resource-table
169169
NEW_VAR: hello
170170
171+
In the above example the environment variables of ``MyFunction`` will be set to:
172+
173+
.. code:: json
174+
175+
{
176+
"STAGE": "Production",
177+
"TABLE_NAME": "resource-table",
178+
"NEW_VAR": "hello"
179+
}
180+
171181
Lists are additive
172182
~~~~~~~~~~~~~~~~~~~
173-
*Also called as arrays*
183+
*Lists are also known as arrays*
174184

175-
List values in the resource will be **appended** with the map value from Global.
185+
Global entries will be **prepended** to the list in the resource.
176186

177187
Example:
178188

179-
SecurityGroupIds of VpcConfig will be set to ``["sg-first", "sg-123", "sg-456"]``
180-
181189
.. code:: yaml
182190
183191
Globals:
@@ -195,3 +203,8 @@ SecurityGroupIds of VpcConfig will be set to ``["sg-first", "sg-123", "sg-456"]`
195203
SecurityGroupIds:
196204
- sg-first
197205
206+
In the above example the Security Group Ids of ``MyFunction``'s VPC Config will be set to:
207+
208+
.. code:: json
209+
210+
[ "sg-123", "sg-456", "sg-first" ]

docs/policy_templates.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,5 @@ folder.
7373
Policies:
7474
- CloudWatchPutMetricPolicy: {}
7575
76-
.. _policy_templates.json: https://github.com/awslabs/serverless-application-model/blob/develop/docs/policy_templates_data/policy_templates.json
76+
.. _policy_templates.json: https://github.com/awslabs/serverless-application-model/blob/develop/samtranslator/policy_templates_data/policy_templates.json
7777
.. _all_policy_templates.yaml: https://github.com/awslabs/serverless-application-model/blob/develop/examples/2016-10-31/policy_templates/all_policy_templates.yaml

0 commit comments

Comments
 (0)