Skip to content

Commit d5814ba

Browse files
authored
Merge pull request #1 from aws/develop
Merge latest
2 parents b134e9e + a07fbec commit d5814ba

File tree

675 files changed

+39187
-5827
lines changed

Some content is hidden

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

675 files changed

+39187
-5827
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
name: Bug report
3+
about: Create an issue to report a bug for the SAM Translator
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
<!-- Make sure we don't have an existing Issue that reports the bug you are seeing (both open and closed).
11+
If you do find an existing Issue, re-open or add a comment to that Issue instead of creating a new one. -->
12+
13+
### Description:
14+
<!-- Briefly describe the bug you are facing.-->
15+
16+
17+
18+
### Steps to reproduce:
19+
<!-- Provide detailed steps to replicate the bug, including steps from third party tools (CDK, etc.) -->
20+
21+
22+
23+
### Observed result:
24+
<!-- Please provide command output with `--debug` flag set.-->
25+
26+
27+
28+
### Expected result:
29+
<!-- Describe what you expected.-->
30+
31+
32+
33+
### Additional environment details (Ex: Windows, Mac, Amazon Linux etc)
34+
35+
1. OS:
36+
2. If using SAM CLI, `sam --version`:
37+
3. AWS region:
38+
39+
`Add --debug flag to any SAM CLI commands you are running`
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
name: Feature request
3+
about: Suggest an idea/feature/enhancement for the SAM Translator
4+
title: ''
5+
labels: ''
6+
assignees: ''
7+
8+
---
9+
10+
<!-- Make sure we don't have an existing Issue for that feature request (open or closed). -->
11+
12+
### Describe your idea/feature/enhancement
13+
14+
Provide a clear description.
15+
16+
Ex: I wish the SAM Translator would [...]
17+
18+
### Proposal
19+
20+
Add details on how to add this to the product.
21+
22+
Things to consider:
23+
[ ] The [SAM documentation](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification.html) will need to be updated
24+
25+
### Additional Details

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
- [ ] `make pr` passes
1111
- [ ] Update documentation
1212
- [ ] Verify transformed template deploys and application functions as expected
13-
- [ ] Add/update example to `examples/2016-10-31`
1413

14+
*Examples?*
15+
16+
Please reach out in the comments, if you want to add an example. Examples will be
17+
added to `sam init` through https://github.com/awslabs/aws-sam-cli-app-templates/
1518

1619
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

.pre-commit-config.yaml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
# https://pre-commit.com/#repository-local-hooks
12
repos:
2-
- repo: https://github.com/python/black
3-
rev: 19.3b0
4-
hooks:
5-
- id: black
6-
language_version: python3.7
7-
exclude_types: ['markdown', 'ini', 'toml', 'rst']
3+
- repo: local
4+
hooks:
5+
- id: black
6+
name: black
7+
entry: black
8+
language: system
9+
types: [python]

.pylintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# pygtk.require().
88
#init-hook=
99

10-
# Add files or directories to the blacklist. They should be base names, not
10+
# Add files or directories to the ignore list. They should be base names, not
1111
# paths.
1212
ignore=compat.py
1313

.travis.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,6 @@ matrix:
2121

2222
install:
2323
# Install the code requirements
24-
- mkdir $HOME/bin-black
25-
- wget -O $HOME/bin-black/black https://github.com/python/black/releases/download/19.10b0/black
26-
- chmod +x $HOME/bin-black/black
27-
- export PATH=$PATH:$HOME/bin-black
28-
- black --version
29-
3024
- make init
3125

3226
# Install Docs requirements

DEVELOPMENT_GUIDE.md

Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
DEVELOPMENT GUIDE
2+
=================
3+
4+
**Welcome hacker!**
5+
6+
This document will make your life easier by helping you setup a
7+
development environment, IDEs, tests, coding practices, or anything that
8+
will help you be more productive. If you found something is missing or
9+
inaccurate, update this guide and send a Pull Request.
10+
11+
**Note**: `pyenv` currently only supports macOS and Linux. If you are a
12+
Windows users, consider using [pipenv](https://docs.pipenv.org/).
13+
14+
1-Click Ready to Hack IDE
15+
-------------------------
16+
For setting up a local development environment, we recommend using Gitpod - a service that allows you to spin up an in-browser Visual Studio Code-compatible editor, with everything set up and ready to go for development on this project. Just click the button below to create your private workspace:
17+
18+
[![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/awslabs/aws-sam-cli)
19+
20+
This will start a new Gitpod workspace, and immediately kick off a build of the code. Once it's done, you can start working.
21+
22+
Gitpod is free for 50 hours per month - make sure to stop your workspace when you're done (you can always resume it later, and it won't need to run the build again).
23+
24+
25+
Environment Setup
26+
-----------------
27+
### 1. Install Python Versions
28+
29+
Our officially supported Python versions are 2.7, 3.6, 3.7 and 3.8. Follow the idioms from this [excellent cheatsheet](http://python-future.org/compatible_idioms.html) to
30+
make sure your code is compatible with both Python 2.7 and 3 (>=3.6) versions.
31+
Our CI/CD pipeline is setup to run unit tests against both Python 2.7 and 3 versions. So make sure you test it with both versions before sending a Pull Request.
32+
See [Unit testing with multiple Python versions](#unit-testing-with-multiple-python-versions).
33+
34+
[pyenv](https://github.com/pyenv/pyenv) is a great tool to
35+
easily setup multiple Python versions. For
36+
37+
> Note: For Windows, type
38+
> `export PATH="/c/Users/<user>/.pyenv/libexec:$PATH"` to add pyenv to
39+
> your path.
40+
41+
1. Install PyEnv -
42+
`curl -L https://github.com/pyenv/pyenv-installer/raw/master/bin/pyenv-installer | bash`
43+
1. Restart shell so the path changes take effect - `exec $SHELL`
44+
1. `pyenv install 2.7.17`
45+
1. `pyenv install 3.6.12`
46+
1. `pyenv install 3.7.9`
47+
1. `pyenv install 3.8.6`
48+
1. Make Python versions available in the project:
49+
`pyenv local 2.7.17 3.6.12 3.7.9 3.8.6`
50+
51+
Note: also make sure the following lines were written into your `.bashrc` (or `.zshrc`, depending on which shell you are using):
52+
```
53+
export PATH="$HOME/.pyenv/bin:$PATH"
54+
eval "$(pyenv init -)"
55+
eval "$(pyenv virtualenv-init -)"
56+
```
57+
58+
### 2. Install Additional Tooling
59+
#### Black
60+
We format our code using [Black](https://github.com/python/black) and verify the source code is black compliant
61+
during PR checks. Black will be installed automatically with `make init`.
62+
63+
After installing, you can run our formatting through our Makefile by `make black` or integrating Black directly in your favorite IDE (instructions
64+
can be found [here](https://black.readthedocs.io/en/stable/editor_integration.html))
65+
66+
##### (workaround) Integrating Black directly in your favorite IDE
67+
Since black is installed in virtualenv, when you follow [this instruction](https://black.readthedocs.io/en/stable/editor_integration.html), `which black` might give you this
68+
69+
```bash
70+
(sam37) $ where black
71+
/Users/<username>/.pyenv/shims/black
72+
```
73+
74+
However, IDEs such PyChaim (using FileWatcher) will have a hard time invoking `/Users/<username>/.pyenv/shims/black`
75+
and this will happen:
76+
77+
```
78+
pyenv: black: command not found
79+
80+
The `black' command exists in these Python versions:
81+
3.7.9/envs/sam37
82+
sam37
83+
```
84+
85+
A simple workaround is to use `/Users/<username>/.pyenv/versions/sam37/bin/black`
86+
instead of `/Users/<username>/.pyenv/shims/black`.
87+
88+
#### Pre-commit
89+
If you don't wish to manually run black on each pr or install black manually, we have integrated black into git hooks through [pre-commit](https://pre-commit.com/).
90+
After installing pre-commit, run `pre-commit install` in the root of the project. This will install black for you and run the black formatting on
91+
commit.
92+
93+
### 3. Activate Virtualenv
94+
95+
Virtualenv allows you to install required libraries outside of the
96+
Python installation. A good practice is to setup a different virtualenv
97+
for each project. [pyenv](https://github.com/pyenv/pyenv) comes with a
98+
handy plugin that can create virtualenv.
99+
100+
Depending on the python version, the following commands would change to
101+
be the appropriate python version.
102+
103+
1. Create Virtualenv `sam37` for Python3.7: `pyenv virtualenv 3.7.9 sam37`
104+
1. Activate Virtualenv: `pyenv activate sam37`
105+
106+
### 4. Install dev version of SAM Translator
107+
108+
We will install a development version of SAM Translator from source into the
109+
virtualenv.
110+
111+
1. Activate Virtualenv: `pyenv activate sam37`
112+
1. Install dev version of SAM Translator: `make init`
113+
114+
Running Tests
115+
-------------
116+
117+
### Unit testing with one Python version
118+
119+
If you're trying to do a quick run, it's ok to use the current python version. Run `make pr`.
120+
If you're using Python2.7, you can run `make pr2.7` instead.
121+
122+
### Unit testing with multiple Python versions
123+
124+
Currently, our officially supported Python versions are 2.7, 3.6, 3.7 and 3.8. For the most
125+
part, code that works in Python3.6 will work in Python3.7 and Python3.8. You only run into problems if you are
126+
trying to use features released in a higher version (for example features introduced into Python3.7
127+
will not work in Python3.6). If you want to test in many versions, you can create a virtualenv for
128+
each version and flip between them (sourcing the activate script). Typically, we run all tests in
129+
one python version locally and then have our ci (appveyor) run all supported versions.
130+
131+
### Integration tests
132+
133+
Integration tests are covered in detail in the [INTEGRATION_TESTS.md file](INTEGRATION_TESTS.md) of this repository.
134+
135+
Code Conventions
136+
----------------
137+
138+
Please follow these code conventions when making your changes. This will
139+
align your code to the same conventions used in rest of the package and
140+
make it easier for others to read/understand your code. Some of these
141+
conventions are best practices that we have learnt over time.
142+
143+
- Don\'t write any code in `__init__.py` file unless there is a really strong reason.
144+
- Module-level logger variable must be named as `LOG`
145+
- If your method wants to report a failure, it *must* raise a custom
146+
exception. Built-in Python exceptions like `TypeError`, `KeyError`
147+
are raised by Python interpreter and usually signify a bug in your
148+
code. Your method must not explicitly raise these exceptions because
149+
the caller has no way of knowing whether it came from a bug or not.
150+
Custom exceptions convey are must better at conveying the intent and
151+
can be handled appropriately by the caller. In HTTP lingo, custom
152+
exceptions are equivalent to 4xx (user\'s fault) and built-in
153+
exceptions are equivalent to 5xx (Service Fault)
154+
- Don't use `*args` or `**kwargs` unless there is a really strong
155+
reason to do so. You must explain the reason in great detail in
156+
docstrings if you were to use them.
157+
- Do not catch the broader `Exception`, unless you have a really
158+
strong reason to do. You must explain the reason in great detail in
159+
comments.
160+
161+
Profiling
162+
---------
163+
164+
Install snakeviz: `pip install snakeviz`
165+
166+
```bash
167+
python -m cProfile -o sam_profile_results bin/sam-translate.py translate --template-file=tests/translator/input/alexa_skill.yaml --output-template=cfn-template.json
168+
snakeviz sam_profile_results
169+
```
170+
171+
Verifying transforms
172+
--------------------
173+
174+
If you make changes to the transformer and want to verify the resulting CloudFormation template works as expected, you can transform your SAM template into a CloudFormation template using the following process:
175+
176+
```bash
177+
# Optional: You only need to run the package command in certain cases; e.g. when your CodeUri specifies a local path
178+
# Replace MY_TEMPLATE_PATH with the path to your template and MY_S3_BUCKET with an existing S3 bucket
179+
aws cloudformation package --template-file MY_TEMPLATE_PATH/template.yaml --output-template-file output-template.yaml --s3-bucket MY_S3_BUCKET
180+
181+
# Transform your SAM template into a CloudFormation template
182+
# Replace "output-template.yaml" if you didn't run the package command above or specified a different path for --output-template-file
183+
bin/sam-translate.py --template-file=output-template.yaml
184+
185+
# Deploy your transformed CloudFormation template
186+
# Replace MY_STACK_NAME with a unique name each time you deploy
187+
aws cloudformation deploy --template-file cfn-template.json --capabilities CAPABILITY_NAMED_IAM --stack-name MY_STACK_NAME
188+
```

0 commit comments

Comments
 (0)