Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
f8e0505
fix: add periods to error messages, fix quotes (#1430)
keetonian Feb 4, 2020
54ab0bc
feat(policy-templates): add EventBridgePutEventsPolicy (#1409)
jmnarloch Feb 11, 2020
8121fcc
fix: use isinstance check instead of type (#1411)
jlhood Feb 13, 2020
ac5b064
feat: add TimeoutInMillis to HttpApi events (#1450)
keetonian Feb 14, 2020
f5353cb
docs: document support for HTTP API Access Log Settings (#1448)
keetonian Feb 20, 2020
77fa3b9
docs: fix markdown style links in not-markdown (#1439)
tyldavis Feb 20, 2020
a1d7e54
feat: add Tags support to Http Api (#1459)
keetonian Feb 21, 2020
58d1dc2
docs: switch Definition to Model (#1423)
dalumiller Feb 24, 2020
477f2bc
chore: merge pull request #1463 from awslabs/master
keetonian Feb 25, 2020
4a991a0
fix: make usageplan properties referable (#1458)
Feb 26, 2020
b834f89
feat: add support for DefaultRouteSettings in HttpApi (#1461)
keetonian Feb 28, 2020
99f5ab7
feat: Trigger auto publish alias on env var/memorysize change (#1310)
Feb 28, 2020
c5221fc
feat: cors httpapi (#1381)
Feb 28, 2020
8650fcb
chore: bump translator version (#1483)
Mar 3, 2020
f928b4b
docs: add referable properties of sam resources (#1468)
Mar 3, 2020
9df2c8a
feat: custom domains in HTTP API (#1472)
praneetap Mar 3, 2020
e2a6dbd
chore: merge pull request #1485 from awslabs/develop
Mar 3, 2020
2d5b209
Fix type of user pool tags (#1460)
keetonian Mar 4, 2020
ef92c3f
feat: add DynamoDBWritePolicy and S3WritePolicy (#1374)
praneetap Mar 4, 2020
7b229d9
feat: support RouteSettings for HttpApi (#1490)
Mar 5, 2020
4fe4fdd
docs: Add StageVariables to docs (#1493)
praneetap Mar 5, 2020
e9c0aa6
feat: propagate tags to DomainName, Stage resources (#1492)
keetonian Mar 5, 2020
aba498f
fix: remove OIDC auth from Http Api (#1491)
praneetap Mar 5, 2020
b741040
chore: merge pull request #1495 from awslabs/develop
Mar 6, 2020
f256529
fix: edge endpoint is not supported in http api yet (#1503)
praneetap Mar 11, 2020
197f806
fix: error when defining $default path in OpenApi (#1498)
keetonian Mar 11, 2020
354445c
fix: remove type property after transformation (#1504)
Mar 11, 2020
d6f9bac
Add support for including path parameters
keetonian Mar 11, 2020
946c991
Add tests for path parameters
keetonian Mar 11, 2020
fbc216c
feat: add support for FailOnWarnings (#1509)
keetonian Mar 11, 2020
287e424
fix(HttpApi): add path parameters if not present (#1510)
Mar 11, 2020
dd1c3d3
chore: merge develop into release/v1.22.0 (#1505)
Mar 11, 2020
7dc8a20
feat: add payloadformatversion to httpapi events (#1517)
Mar 16, 2020
19ed4a0
chore: merge pull request #1520
Mar 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions DEVELOPMENT_GUIDE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ Setup Python locally using `pyenv`_
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1. Black
~~~~~~~~
We format our code using [Black](https://github.com/python/black) and verify the source code is black compliant
in Appveyor during PRs. You can find installation instructions on [Black's docs](https://black.readthedocs.io/en/stable/installation_and_usage.html).
We format our code using `Black`_ and verify the source code is black compliant
in Appveyor during PRs. You can find installation instructions on `Black's docs`_.

After installing, you can check your formatting through our Makefile by running `make black-check`. To automatically update your code to match our formatting, please run `make black`. You can also integrate Black directly in your favorite IDE (instructions
can be found [here](https://black.readthedocs.io/en/stable/editor_integration.html))
can be found `here`_)

Pre-commit
~~~~~~~~~~
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/).
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`_.
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
commit.

Expand Down Expand Up @@ -85,6 +85,10 @@ Tests are also a documentation of the success and failure cases, which is crucia
.. _pyenv: https://github.com/pyenv/pyenv
.. _tox: http://tox.readthedocs.io/en/latest/
.. _installation instructions: https://github.com/pyenv/pyenv#installation
.. _Black: https://github.com/python/black
.. _Black's docs: https://black.readthedocs.io/en/stable/installation_and_usage.html
.. _here: https://black.readthedocs.io/en/stable/editor_integration.html
.. _pre-commit: https://pre-commit.com/

Profiling
---------
Expand Down
6 changes: 6 additions & 0 deletions docs/globals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ Currently, the following resources and properties are being supported:
# Properties of AWS::Serverless::HttpApi
# Also works with Implicit APIs
Auth:
CorsConfiguration:
AccessLogSettings:
Tags:
DefaultRouteSettings:
RouteSettings:
Domain:

SimpleTable:
# Properties of AWS::Serverless::SimpleTable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Resources:
Path: /fetch

MyApi:
Type: AWS::Serverless::Api
Type: AWS::Serverless::Api # Also works with HTTP API
Properties:
OpenApiVersion: 3.0.1
StageName: Prod
Expand Down
12 changes: 12 additions & 0 deletions examples/2016-10-31/http_api_cors/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# HttpApi with CORS Example

Example SAM template to configure CORS for HttpApi

## Running the example

```bash
$ sam deploy \
--template-file template.yaml \
--stack-name my-stack-name \
--capabilities CAPABILITY_IAM
```
48 changes: 48 additions & 0 deletions examples/2016-10-31/http_api_cors/template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
AWSTemplateFormatVersion : '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Http Api with Cors.

Resources:
HttpApiFunction:
Type: AWS::Serverless::Function
Properties:
InlineCode: |
exports.handler = async (event) => {
console.log("Hello from MyAuthFunction")
return {
statusCode: 200,
body: JSON.stringify(event),
headers: {}
}
}
Handler: index.handler
Runtime: nodejs12.x
Events:
SimpleCase:
Type: HttpApi
Properties:
ApiId: !Ref MyApi

MyApi:
Type: AWS::Serverless::HttpApi
Properties:
FailOnWarnings: true
CorsConfiguration:
AllowHeaders:
- x-apigateway-header
AllowMethods:
- GET
AllowOrigins:
- https://foo.com
ExposeHeaders:
- x-amzn-header
DefinitionBody:
info:
version: '1.0'
title:
Ref: AWS::StackName
paths:
"$default":
x-amazon-apigateway-any-method:
isDefaultRoute: true
openapi: 3.0.1
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ Resources:
- DynamoDBReadPolicy:
TableName: name

- DynamoDBWritePolicy:
TableName: name

- SESSendBouncePolicy:
IdentityName: name

Expand All @@ -38,6 +41,9 @@ Resources:
- S3CrudPolicy:
BucketName: name

- S3WritePolicy:
BucketName: name

- AMIDescribePolicy: {}

- CloudFormationDescribeStacksPolicy: {}
Expand Down Expand Up @@ -107,3 +113,6 @@ Resources:
- TextractDetectAnalyzePolicy: {}

- TextractGetResultPolicy: {}

- EventBridgePutEventsPolicy:
EventBusName: name
2 changes: 1 addition & 1 deletion samtranslator/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.21.0"
__version__ = "1.22.0"
50 changes: 29 additions & 21 deletions samtranslator/model/api/api_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from samtranslator.model.s3_utils.uri_parser import parse_s3_uri
from samtranslator.region_configuration import RegionConfiguration
from samtranslator.swagger.swagger import SwaggerEditor
from samtranslator.model.intrinsics import is_instrinsic, fnSub
from samtranslator.model.intrinsics import is_intrinsic, fnSub
from samtranslator.model.lambda_ import LambdaPermission
from samtranslator.translator import logical_id_generator
from samtranslator.translator.arn_generator import ArnGenerator
Expand Down Expand Up @@ -154,15 +154,15 @@ def _construct_rest_api(self):

if self.definition_uri and self.definition_body:
raise InvalidResourceException(
self.logical_id, "Specify either 'DefinitionUri' or 'DefinitionBody' property and not both"
self.logical_id, "Specify either 'DefinitionUri' or 'DefinitionBody' property and not both."
)

if self.open_api_version:
if not SwaggerEditor.safe_compare_regex_with_string(
SwaggerEditor.get_openapi_versions_supported_regex(), self.open_api_version
):
raise InvalidResourceException(
self.logical_id, 'The OpenApiVersion value must be of the format "3.0.0"'
self.logical_id, "The OpenApiVersion value must be of the format '3.0.0'."
)

self._add_cors()
Expand Down Expand Up @@ -193,7 +193,7 @@ def _construct_body_s3_dict(self):
if not self.definition_uri.get("Bucket", None) or not self.definition_uri.get("Key", None):
# DefinitionUri is a dictionary but does not contain Bucket or Key property
raise InvalidResourceException(
self.logical_id, "'DefinitionUri' requires Bucket and Key properties to be specified"
self.logical_id, "'DefinitionUri' requires Bucket and Key properties to be specified."
)
s3_pointer = self.definition_uri

Expand All @@ -205,7 +205,7 @@ def _construct_body_s3_dict(self):
raise InvalidResourceException(
self.logical_id,
"'DefinitionUri' is not a valid S3 Uri of the form "
'"s3://bucket/key" with optional versionId query parameter.',
"'s3://bucket/key' with optional versionId query parameter.",
)

body_s3 = {"Bucket": s3_pointer["Bucket"], "Key": s3_pointer["Key"]}
Expand Down Expand Up @@ -276,7 +276,7 @@ def _construct_api_domain(self, rest_api):

if self.domain.get("DomainName") is None or self.domain.get("CertificateArn") is None:
raise InvalidResourceException(
self.logical_id, "Custom Domains only works if both DomainName and CertificateArn" " are provided"
self.logical_id, "Custom Domains only works if both DomainName and CertificateArn" " are provided."
)

self.domain["ApiDomainName"] = "{}{}".format(
Expand All @@ -293,7 +293,7 @@ def _construct_api_domain(self, rest_api):
elif endpoint not in ["EDGE", "REGIONAL"]:
raise InvalidResourceException(
self.logical_id,
"EndpointConfiguration for Custom Domains must be" " one of {}".format(["EDGE", "REGIONAL"]),
"EndpointConfiguration for Custom Domains must be" " one of {}.".format(["EDGE", "REGIONAL"]),
)

if endpoint == "REGIONAL":
Expand Down Expand Up @@ -427,10 +427,10 @@ def _add_cors(self):

if self.cors and not self.definition_body:
raise InvalidResourceException(
self.logical_id, "Cors works only with inline Swagger specified in " "'DefinitionBody' property"
self.logical_id, "Cors works only with inline Swagger specified in 'DefinitionBody' property."
)

if isinstance(self.cors, string_types) or is_instrinsic(self.cors):
if isinstance(self.cors, string_types) or is_intrinsic(self.cors):
# Just set Origin property. Others will be defaults
properties = CorsProperties(AllowOrigin=self.cors)
elif isinstance(self.cors, dict):
Expand All @@ -447,7 +447,8 @@ def _add_cors(self):
if not SwaggerEditor.is_valid(self.definition_body):
raise InvalidResourceException(
self.logical_id,
"Unable to add Cors configuration because " "'DefinitionBody' does not contain a valid Swagger",
"Unable to add Cors configuration because "
"'DefinitionBody' does not contain a valid Swagger definition.",
)

if properties.AllowCredentials is True and properties.AllowOrigin == _CORS_WILDCARD:
Expand Down Expand Up @@ -500,7 +501,7 @@ def _add_auth(self):

if self.auth and not self.definition_body:
raise InvalidResourceException(
self.logical_id, "Auth works only with inline Swagger specified in " "'DefinitionBody' property"
self.logical_id, "Auth works only with inline Swagger specified in " "'DefinitionBody' property."
)

# Make sure keys in the dict are recognized
Expand All @@ -510,7 +511,8 @@ def _add_auth(self):
if not SwaggerEditor.is_valid(self.definition_body):
raise InvalidResourceException(
self.logical_id,
"Unable to add Auth configuration because " "'DefinitionBody' does not contain a valid Swagger",
"Unable to add Auth configuration because "
"'DefinitionBody' does not contain a valid Swagger definition.",
)
swagger_editor = SwaggerEditor(self.definition_body)
auth_properties = AuthProperties(**self.auth)
Expand Down Expand Up @@ -565,10 +567,10 @@ def _construct_usage_plan(self, rest_api_stage=None):
usage_plan_key = None

if create_usage_plan is None:
raise InvalidResourceException(self.logical_id, "'CreateUsagePlan' is a required field for UsagePlan")
raise InvalidResourceException(self.logical_id, "'CreateUsagePlan' is a required field for UsagePlan.")
if create_usage_plan not in create_usage_plans_accepted_values:
raise InvalidResourceException(
self.logical_id, "'CreateUsagePlan' accepts one of {}".format(create_usage_plans_accepted_values)
self.logical_id, "'CreateUsagePlan' accepts one of {}.".format(create_usage_plans_accepted_values)
)

if create_usage_plan == "NONE":
Expand Down Expand Up @@ -683,7 +685,7 @@ def _add_gateway_responses(self):
if self.gateway_responses and not self.definition_body:
raise InvalidResourceException(
self.logical_id,
"GatewayResponses works only with inline Swagger specified in " "'DefinitionBody' property",
"GatewayResponses works only with inline Swagger specified in " "'DefinitionBody' property.",
)

# Make sure keys in the dict are recognized
Expand All @@ -692,13 +694,16 @@ def _add_gateway_responses(self):
if response_key not in GatewayResponseProperties:
raise InvalidResourceException(
self.logical_id,
"Invalid property '{}' in 'GatewayResponses' property '{}'".format(response_key, responses_key),
"Invalid property '{}' in 'GatewayResponses' property '{}'.".format(
response_key, responses_key
),
)

if not SwaggerEditor.is_valid(self.definition_body):
raise InvalidResourceException(
self.logical_id,
"Unable to add Auth configuration because " "'DefinitionBody' does not contain a valid Swagger",
"Unable to add Auth configuration because "
"'DefinitionBody' does not contain a valid Swagger definition.",
)

swagger_editor = SwaggerEditor(self.definition_body)
Expand Down Expand Up @@ -729,13 +734,14 @@ def _add_models(self):

if self.models and not self.definition_body:
raise InvalidResourceException(
self.logical_id, "Models works only with inline Swagger specified in " "'DefinitionBody' property"
self.logical_id, "Models works only with inline Swagger specified in " "'DefinitionBody' property."
)

if not SwaggerEditor.is_valid(self.definition_body):
raise InvalidResourceException(
self.logical_id,
"Unable to add Models definitions because " "'DefinitionBody' does not contain a valid Swagger",
"Unable to add Models definitions because "
"'DefinitionBody' does not contain a valid Swagger definition.",
)

if not all(isinstance(model, dict) for model in self.models.values()):
Expand Down Expand Up @@ -818,7 +824,7 @@ def _get_authorizers(self, authorizers_config, default_authorizer=None):
return None

if not isinstance(authorizers_config, dict):
raise InvalidResourceException(self.logical_id, "Authorizers must be a dictionary")
raise InvalidResourceException(self.logical_id, "Authorizers must be a dictionary.")

for authorizer_name, authorizer in authorizers_config.items():
if not isinstance(authorizer, dict):
Expand Down Expand Up @@ -895,7 +901,9 @@ def _set_default_authorizer(
if not authorizers.get(default_authorizer) and default_authorizer != "AWS_IAM":
raise InvalidResourceException(
self.logical_id,
"Unable to set DefaultAuthorizer because '" + default_authorizer + "' was not defined in 'Authorizers'",
"Unable to set DefaultAuthorizer because '"
+ default_authorizer
+ "' was not defined in 'Authorizers'.",
)

for path in swagger_editor.iter_on_path():
Expand Down
Loading