Skip to content

Commit

Permalink
Merge branch 'develop' into feat/allow-canned-acl-with-s3-crud-policy
Browse files Browse the repository at this point in the history
  • Loading branch information
keetonian committed Jan 18, 2019
2 parents bde4d1b + 2f608b6 commit f868502
Show file tree
Hide file tree
Showing 173 changed files with 5,886 additions and 1,631 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[flake8]
max-line-length = 120
ignore = E126
ignore = E126 F821 W504 W605
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ init:
$(info [*] Install requirements...)
@pip install -r requirements/dev.txt -r requirements/base.txt

flake:
$(info [*] Running flake8...)
@flake8 samtranslator

test:
$(info [*] Run the unit test with minimum code coverage of $(CODE_COVERAGE)%...)
@pytest --cov samtranslator --cov-report term-missing --cov-fail-under $(CODE_COVERAGE) tests
Expand All @@ -49,7 +53,7 @@ build-docs:
@$(MAKE) -C docs/website html

# Command to run everytime you make changes to verify everything works
dev: test
dev: flake test

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

endef
endef
1 change: 1 addition & 0 deletions docs/cloudformation_compatibility.rst
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ EndpointConfiguration All
MethodSettings All
BinaryMediaTypes All
Cors All
TracingEnabled All
================================== ======================== ========================


Expand Down
3 changes: 3 additions & 0 deletions docs/globals.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ Currently, the following resources and properties are being supported:
MethodSettings:
BinaryMediaTypes:
Cors:
AccessLogSetting:
CanarySetting:
TracingEnabled:
SimpleTable:
# Properties of AWS::Serverless::SimpleTable
Expand Down
4 changes: 4 additions & 0 deletions examples/2016-10-31/api_cognito_auth/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Resources:
RestApiId: !Ref MyApi
Path: /
Method: GET
# NOTE: This endpoint is publicly accessible
Auth:
Authorizer: NONE
ProxyAny:
Expand All @@ -48,6 +49,7 @@ Resources:
RestApiId: !Ref MyApi
Path: /{proxy+}
Method: ANY
# NOTE: This endpoint is publicly accessible
Auth:
Authorizer: NONE
GetUsers:
Expand All @@ -56,6 +58,7 @@ Resources:
RestApiId: !Ref MyApi
Path: /users
Method: GET
# NOTE: This endpoint is publicly accessible
Auth:
Authorizer: NONE
GetUser:
Expand All @@ -64,6 +67,7 @@ Resources:
RestApiId: !Ref MyApi
Path: /users/{userId}
Method: GET
# NOTE: This endpoint is publicly accessible
Auth:
Authorizer: NONE
CreateUser:
Expand Down
9 changes: 8 additions & 1 deletion examples/2016-10-31/api_lambda_request_auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ The Authorizer Lambda Function in this example simply accepts an `auth` query st

## Running the example

Optional: Uncomment the following lines in `template.yaml` to enable a publicly accessible endpoint:

```yaml
# Auth:
# Authorizer: NONE
```

Deploy the example into your account:

```bash
Expand All @@ -15,7 +22,7 @@ aws cloudformation package --template-file template.yaml --output-template-file
aws cloudformation deploy --template-file ./template.packaged.yaml --stack-name sam-example-api-lambda-request-auth --capabilities CAPABILITY_IAM
```

Invoke the API's root endpoint `/` without an `auth` query string to see the API respond with a 200. In the SAM template, we explicitly state `Authorizer: NONE` to make this a public/open endpoint (the Authorizer Lambda Function is not invoked).
Invoke the API's root endpoint `/` without an `auth` query string to see the API respond with a 200 (assuming you followed the optional step above). In the SAM template, we explicitly state `Authorizer: NONE` to make this a public/open endpoint (the Authorizer Lambda Function is not invoked).

```bash
api_url=$(aws cloudformation describe-stacks --stack-name sam-example-api-lambda-request-auth --query 'Stacks[].Outputs[?OutputKey==`ApiURL`].OutputValue' --output text)
Expand Down
5 changes: 3 additions & 2 deletions examples/2016-10-31/api_lambda_request_auth/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ Resources:
RestApiId: !Ref MyApi
Path: /
Method: get
Auth:
Authorizer: NONE
# NOTE: Uncomment the two lines below to make `GET /` publicly accessible
# Auth:
# Authorizer: NONE
GetUsers:
Type: Api
Properties:
Expand Down
9 changes: 8 additions & 1 deletion examples/2016-10-31/api_lambda_token_auth/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ The Authorizer Lambda Function in this example simply accepts an `Authorization`

## Running the example

Optional: Uncomment the following lines in `template.yaml` to enable a publicly accessible endpoint:

```yaml
# Auth:
# Authorizer: NONE
```

Deploy the example into your account:

```bash
Expand All @@ -15,7 +22,7 @@ aws cloudformation package --template-file template.yaml --output-template-file
aws cloudformation deploy --template-file ./template.packaged.yaml --stack-name sam-example-api-lambda-token-auth --capabilities CAPABILITY_IAM
```

Invoke the API's root endpoint `/` without an `Authorization` header to see the API respond with a 200. In the SAM template, we explicitly state `Authorizer: NONE` to make this a public/open endpoint (the Authorizer Lambda Function is not invoked).
Invoke the API's root endpoint `/` without an `Authorization` header to see the API respond with a 200 (assuming you followed the optional step above). In the SAM template, we explicitly state `Authorizer: NONE` to make this a public/open endpoint (the Authorizer Lambda Function is not invoked).

```bash
curl "$(aws cloudformation describe-stacks --stack-name sam-example-api-lambda-token-auth --query 'Stacks[].Outputs[?OutputKey==`ApiURL`].OutputValue' --output text)"
Expand Down
5 changes: 3 additions & 2 deletions examples/2016-10-31/api_lambda_token_auth/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ Resources:
RestApiId: !Ref MyApi
Path: /
Method: get
Auth:
Authorizer: NONE
# NOTE: Uncomment the two lines below to make `GET /` publicly accessible
# Auth:
# Authorizer: NONE
GetUsers:
Type: Api
Properties:
Expand Down
35 changes: 35 additions & 0 deletions examples/2016-10-31/lambda_sns_filter_policy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Lambda function + Filtered SNS Subscription Example

This example shows you how to create a Lambda function with a SNS event source.

The Lambda function does not receive all messages published to the SNS topic but only a subset. The messages are filtered based on the attributes attached to
the message.

## Running the example

Deploy the example into your account:

```bash
# Replace YOUR_S3_ARTIFACTS_BUCKET with the name of a bucket which already exists in your account
aws cloudformation package --template-file template.yaml --output-template-file template.packaged.yaml --s3-bucket YOUR_S3_ARTIFACTS_BUCKET

aws cloudformation deploy --template-file ./template.packaged.yaml --stack-name sam-example-lambda-sns-filter-policy --capabilities CAPABILITY_IAM
```

The Lambda function will only receive messages with the attribute `sport` set to `football`.

In the AWS console go to the topic sam-example-lambda-sns-filter-policy and push the Publish to Topic button.
At the bottom of the Publish page you can add message attributes. Add one attribute:
- key: sport
- Attribute type: String
- value: football

Enter an arbitrary message body and publish the message.
In Cloudwatch the log group /aws/lambda/sam-example-lambda-sns-filter-policy-notification-logger appears and the logging contains the message attributes of
the received message.

Now publish a couple of other messages with other values for the attribute `sport` or without the attribute `sport`.
The Lambda function will not receive these messages.

## Additional resources
https://docs.aws.amazon.com/sns/latest/dg/message-filtering.html
8 changes: 8 additions & 0 deletions examples/2016-10-31/lambda_sns_filter_policy/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
'use strict';


exports.handler = async (event, context, callback) => {
console.log("Message attributes: " + JSON.stringify(event.Records[0].Sns.MessageAttributes));

callback(null, "Success");
};
24 changes: 24 additions & 0 deletions examples/2016-10-31/lambda_sns_filter_policy/template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: Lambda function with SNS filter policy
Resources:
NotificationLogger:
Type: AWS::Serverless::Function
Properties:
CodeUri: ./src
Handler: index.handler
Runtime: nodejs8.10
FunctionName: sam-example-lambda-sns-filter-policy-notification-logger
Events:
NotificationTopic:
Type: SNS
Properties:
Topic: !Ref Notifications
FilterPolicy:
sport:
- football

Notifications:
Type: AWS::SNS::Topic
Properties:
TopicName: sam-example-lambda-sns-filter-policy
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,8 @@ Resources:
- KMSDecryptPolicy:
KeyId: keyId

- SESBulkTemplatedCrudPolicy:
IdentityName: name

- FilterLogEventsPolicy:
LogGroupName: name
3 changes: 2 additions & 1 deletion examples/apps/api-gateway-authorizer-nodejs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,8 @@ AuthPolicy.prototype = (function AuthPolicyClass() {


exports.handler = (event, context, callback) => {
console.log('Client token:', event.authorizationToken);
// incoming token value
var token = event.authorizationToken;
console.log('Method ARN:', event.methodArn);

// validate the incoming token
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@


def lambda_handler(event, context):
print("Client token: " + event['authorizationToken'])
# incoming token value
token = event['authorizationToken']
print("Method ARN: " + event['methodArn'])

'''
Expand Down
7 changes: 5 additions & 2 deletions examples/apps/rekognition-python/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: An Amazon S3 trigger that uses rekognition APIs to detect faces
Parameters:
BucketNameParameter:
BucketNamePrefix:
Type: String
Default: sam-example
CollectionIdParameter:
Type: String
Resources:
Expand All @@ -18,7 +19,7 @@ Resources:
Timeout: 3
Policies:
- S3CrudPolicy:
BucketName: !Ref BucketNameParameter
BucketName: !Sub "${BucketNamePrefix}-rekognition"
- RekognitionNoDataAccessPolicy:
CollectionId: !Ref CollectionIdParameter
- RekognitionWriteOnlyAccessPolicy:
Expand All @@ -33,3 +34,5 @@ Resources:
- 's3:ObjectCreated:*'
Bucket1:
Type: 'AWS::S3::Bucket'
Properties:
BucketName: !Sub "${BucketNamePrefix}-rekognition"
7 changes: 5 additions & 2 deletions examples/apps/s3-get-object-python/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Description: >-
An Amazon S3 trigger that retrieves metadata for the object that has been
updated.
Parameters:
BucketNameParameter:
BucketNamePrefix:
Type: String
Default: sam-example
Resources:
s3getobjectpython:
Type: 'AWS::Serverless::Function'
Expand All @@ -20,7 +21,7 @@ Resources:
Timeout: 3
Policies:
- S3CrudPolicy:
BucketName: !Ref BucketNameParameter
BucketName: !Sub "${BucketNamePrefix}-get-object-python"
Events:
BucketEvent1:
Type: S3
Expand All @@ -31,3 +32,5 @@ Resources:
- 's3:ObjectCreated:*'
Bucket1:
Type: 'AWS::S3::Bucket'
Properties:
BucketName: !Sub "${BucketNamePrefix}-get-object-python"
7 changes: 5 additions & 2 deletions examples/apps/s3-get-object-python3/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Description: >-
An Amazon S3 trigger that retrieves metadata for the object that has been
updated.
Parameters:
BucketNameParameter:
BucketNamePrefix:
Type: String
Default: sam-example
Resources:
s3getobjectpython3:
Type: 'AWS::Serverless::Function'
Expand All @@ -20,7 +21,7 @@ Resources:
Timeout: 3
Policies:
- S3CrudPolicy:
BucketName: !Ref BucketNameParameter
BucketName: !Sub "${BucketNamePrefix}-get-object-python3"
Events:
BucketEvent1:
Type: S3
Expand All @@ -31,3 +32,5 @@ Resources:
- 's3:ObjectCreated:*'
Bucket1:
Type: 'AWS::S3::Bucket'
Properties:
BucketName: !Sub "${BucketNamePrefix}-get-object-python3"
10 changes: 6 additions & 4 deletions examples/apps/s3-get-object/template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ Description: >-
An Amazon S3 trigger that retrieves metadata for the object that has been
updated.
Parameters:
BucketNameParameter:
BucketNamePrefix:
Type: String
Default: sam-example
Resources:
s3getobject:
Type: 'AWS::Serverless::Function'
Expand All @@ -20,14 +21,15 @@ Resources:
Timeout: 3
Policies:
- S3CrudPolicy:
BucketName: !Ref BucketNameParameter
BucketName: !Sub "${BucketNamePrefix}-get-object"
Events:
BucketEvent1:
Type: S3
Properties:
Bucket:
Ref: Bucket1
Bucket: !Ref Bucket1
Events:
- 's3:ObjectCreated:*'
Bucket1:
Type: 'AWS::S3::Bucket'
Properties:
BucketName: !Sub "${BucketNamePrefix}-get-object"
3 changes: 1 addition & 2 deletions requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ PyYAML==3.12
pytest>=3.0.7
py>=1.4.33
mock>=2.0.0
nose>=1.3.7
parameterized>=0.6.1
requests>=2.11.1
requests>=2.20.0

# CLI requirements
docopt>=0.6.2
2 changes: 1 addition & 1 deletion samtranslator/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '1.9.0'
__version__ = '1.10.0'
Loading

0 comments on commit f868502

Please sign in to comment.