Skip to content

Instantly share code, notes, and snippets.

@jamesls
Created March 28, 2018 22:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamesls/c80880fb7df39bc33ef4d30aca7d6995 to your computer and use it in GitHub Desktop.
Save jamesls/c80880fb7df39bc33ef4d30aca7d6995 to your computer and use it in GitHub Desktop.
Given this app.py
from chalice import Chalice
app = Chalice(app_name='sam-compare')
@app.authorizer()
def myauth(auth_event):
return None
@app.lambda_function()
def foo(event, context):
return None
@app.schedule('rate(5 minutes)')
def cron(event):
return None
@app.route('/', authorizer=myauth)
def index():
return {'hello': 'world'}
The old chalice package command gives:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Outputs": {
"RestAPIId": {
"Value": {
"Ref": "RestAPI"
}
},
"APIHandlerName": {
"Value": {
"Ref": "APIHandler"
}
},
"APIHandlerArn": {
"Value": {
"Fn::GetAtt": [
"APIHandler",
"Arn"
]
}
},
"EndpointURL": {
"Value": {
"Fn::Sub": "https://${RestAPI}.execute-api.${AWS::Region}.amazonaws.com/api/"
}
}
},
"Transform": "AWS::Serverless-2016-10-31",
"Resources": {
"RestAPI": {
"Type": "AWS::Serverless::Api",
"Properties": {
"DefinitionBody": {
"info": {
"version": "1.0",
"title": "sam-compare"
},
"paths": {
"/": {
"get": {
"responses": {
"200": {
"description": "200 response",
"schema": {
"$ref": "#/definitions/Empty"
}
}
},
"security": [
{
"myauth": []
}
],
"x-amazon-apigateway-integration": {
"contentHandling": "CONVERT_TO_TEXT",
"responses": {
"default": {
"statusCode": "200"
}
},
"uri": {
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${APIHandler.Arn}/invocations"
},
"httpMethod": "POST",
"passthroughBehavior": "when_no_match",
"type": "aws_proxy"
},
"consumes": [
"application/json"
],
"produces": [
"application/json"
]
}
}
},
"schemes": [
"https"
],
"securityDefinitions": {
"myauth": {
"x-amazon-apigateway-authtype": "custom",
"type": "apiKey",
"name": "Authorization",
"x-amazon-apigateway-authorizer": {
"authorizerUri": {
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${myauthdb6d.Arn}/invocations"
},
"type": "token"
},
"in": "header"
}
},
"x-amazon-apigateway-binary-media-types": [
"application/octet-stream",
"application/x-tar",
"application/zip",
"audio/basic",
"audio/ogg",
"audio/mp4",
"audio/mpeg",
"audio/wav",
"audio/webm",
"image/png",
"image/jpg",
"image/gif",
"video/ogg",
"video/mpeg",
"video/webm"
],
"definitions": {
"Empty": {
"type": "object",
"title": "Empty Schema"
}
},
"swagger": "2.0"
},
"StageName": "api"
}
},
"myauthdb6d": {
"Type": "AWS::Serverless::Function",
"Properties": {
"Policies": [
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*",
"Effect": "Allow"
}
]
}
],
"Tags": {
"aws-chalice": "version=1.1.1:stage=dev:app=sam-compare"
},
"MemorySize": 128,
"Handler": "app.myauth",
"Timeout": 60,
"CodeUri": "./deployment.zip",
"Runtime": "python2.7",
"Events": {}
}
},
"APIHandler": {
"Type": "AWS::Serverless::Function",
"Properties": {
"Policies": [
{
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*",
"Effect": "Allow"
}
]
}
],
"Tags": {
"aws-chalice": "version=1.1.1:stage=dev:app=sam-compare"
},
"MemorySize": 128,
"Handler": "app.app",
"Timeout": 60,
"CodeUri": "./deployment.zip",
"Runtime": "python2.7",
"Events": {
"indexget6bb1": {
"Type": "Api",
"Properties": {
"Path": "/",
"RestApiId": {
"Ref": "RestAPI"
},
"Method": "get"
}
}
}
}
},
"myauthdb6dInvokePermission": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Fn::GetAtt": [
"myauthdb6d",
"Arn"
]
},
"Principal": "apigateway.amazonaws.com"
}
}
}
}
The new package command gives:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Outputs": {
"APIHandlerArn": {
"Value": {
"Fn::GetAtt": [
"APIHandler",
"Arn"
]
}
},
"APIHandlerName": {
"Value": {
"Ref": "APIHandler"
}
},
"RestAPIId": {
"Value": {
"Ref": "RestAPI"
}
},
"EndpointURL": {
"Value": {
"Fn::Sub": "https://${RestAPI}.execute-api.${AWS::Region}.amazonaws.com/api/"
}
}
},
"Transform": "AWS::Serverless-2016-10-31",
"Resources": {
"myauthdb6dInvokePermission": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Fn::GetAtt": [
"myauthdb6d",
"Arn"
]
},
"SourceArn": {
"Fn::Sub": [
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${RestAPIId}/*",
{
"RestAPIId": {
"Ref": "RestAPI"
}
}
]
},
"Principal": "apigateway.amazonaws.com"
}
},
"RestAPI": {
"Type": "AWS::Serverless::Api",
"Properties": {
"DefinitionBody": {
"info": {
"version": "1.0",
"title": "sam-compare"
},
"paths": {
"/": {
"get": {
"responses": {
"200": {
"description": "200 response",
"schema": {
"$ref": "#/definitions/Empty"
}
}
},
"security": [
{
"myauth": []
}
],
"x-amazon-apigateway-integration": {
"contentHandling": "CONVERT_TO_TEXT",
"responses": {
"default": {
"statusCode": "200"
}
},
"uri": {
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${APIHandler.Arn}/invocations"
},
"httpMethod": "POST",
"passthroughBehavior": "when_no_match",
"type": "aws_proxy"
},
"consumes": [
"application/json"
],
"produces": [
"application/json"
]
}
}
},
"schemes": [
"https"
],
"securityDefinitions": {
"myauth": {
"x-amazon-apigateway-authtype": "custom",
"type": "apiKey",
"name": "Authorization",
"x-amazon-apigateway-authorizer": {
"authorizerUri": {
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${myauthdb6d.Arn}/invocations"
},
"type": "token"
},
"in": "header"
}
},
"x-amazon-apigateway-binary-media-types": [
"application/octet-stream",
"application/x-tar",
"application/zip",
"audio/basic",
"audio/ogg",
"audio/mp4",
"audio/mpeg",
"audio/wav",
"audio/webm",
"image/png",
"image/jpg",
"image/jpeg",
"image/gif",
"video/ogg",
"video/mpeg",
"video/webm"
],
"definitions": {
"Empty": {
"type": "object",
"title": "Empty Schema"
}
},
"swagger": "2.0"
},
"StageName": "api"
}
},
"APIHandler": {
"Type": "AWS::Serverless::Function",
"Properties": {
"Policies": {
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*",
"Effect": "Allow"
}
]
},
"Tags": {
"aws-chalice": "version=1.1.1:stage=dev:app=sam-compare"
},
"MemorySize": 128,
"Handler": "app.app",
"Timeout": 60,
"CodeUri": "./deployment.zip",
"Runtime": "python2.7"
}
},
"myauthdb6d": {
"Type": "AWS::Serverless::Function",
"Properties": {
"Policies": {
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*",
"Effect": "Allow"
}
]
},
"Tags": {
"aws-chalice": "version=1.1.1:stage=dev:app=sam-compare"
},
"MemorySize": 128,
"Handler": "app.myauth",
"Timeout": 60,
"CodeUri": "./deployment.zip",
"Runtime": "python2.7"
}
},
"APIHandlerInvokePermission": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "APIHandler"
},
"SourceArn": {
"Fn::Sub": [
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${RestAPIId}/*",
{
"RestAPIId": {
"Ref": "RestAPI"
}
}
]
},
"Principal": "apigateway.amazonaws.com"
}
},
"cron9d3b": {
"Type": "AWS::Serverless::Function",
"Properties": {
"Policies": {
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*",
"Effect": "Allow"
}
]
},
"Tags": {
"aws-chalice": "version=1.1.1:stage=dev:app=sam-compare"
},
"MemorySize": 128,
"Handler": "app.cron",
"Timeout": 60,
"CodeUri": "./deployment.zip",
"Runtime": "python2.7",
"Events": {
"cronevente2de": {
"Type": "Schedule",
"Properties": {
"Schedule": "rate(5 minutes)"
}
}
}
}
},
"fooacbd": {
"Type": "AWS::Serverless::Function",
"Properties": {
"Policies": {
"Version": "2012-10-17",
"Statement": [
{
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*",
"Effect": "Allow"
}
]
},
"Tags": {
"aws-chalice": "version=1.1.1:stage=dev:app=sam-compare"
},
"MemorySize": 128,
"Handler": "app.foo",
"Timeout": 60,
"CodeUri": "./deployment.zip",
"Runtime": "python2.7"
}
}
}
}
The json-diff is:
{
Resources: {
+ APIHandlerInvokePermission: {
+ Type: "AWS::Lambda::Permission"
+ Properties: {
+ Action: "lambda:InvokeFunction"
+ FunctionName: {
+ Ref: "APIHandler"
+ }
+ SourceArn: {
+ Fn::Sub: [
+ "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${RestAPIId}/*"
+ {
+ RestAPIId: {
+ Ref: "RestAPI"
+ }
+ }
+ ]
+ }
+ Principal: "apigateway.amazonaws.com"
+ }
+ }
+ cron9d3b: {
+ Type: "AWS::Serverless::Function"
+ Properties: {
+ Policies: {
+ Version: "2012-10-17"
+ Statement: [
+ {
+ Action: [
+ "logs:CreateLogGroup"
+ "logs:CreateLogStream"
+ "logs:PutLogEvents"
+ ]
+ Resource: "arn:aws:logs:*:*:*"
+ Effect: "Allow"
+ }
+ ]
+ }
+ Tags: {
+ aws-chalice: "version=1.1.1:stage=dev:app=sam-compare"
+ }
+ MemorySize: 128
+ Handler: "app.cron"
+ Timeout: 60
+ CodeUri: "./deployment.zip"
+ Runtime: "python2.7"
+ Events: {
+ cronevente2de: {
+ Type: "Schedule"
+ Properties: {
+ Schedule: "rate(5 minutes)"
+ }
+ }
+ }
+ }
+ }
+ fooacbd: {
+ Type: "AWS::Serverless::Function"
+ Properties: {
+ Policies: {
+ Version: "2012-10-17"
+ Statement: [
+ {
+ Action: [
+ "logs:CreateLogGroup"
+ "logs:CreateLogStream"
+ "logs:PutLogEvents"
+ ]
+ Resource: "arn:aws:logs:*:*:*"
+ Effect: "Allow"
+ }
+ ]
+ }
+ Tags: {
+ aws-chalice: "version=1.1.1:stage=dev:app=sam-compare"
+ }
+ MemorySize: 128
+ Handler: "app.foo"
+ Timeout: 60
+ CodeUri: "./deployment.zip"
+ Runtime: "python2.7"
+ }
+ }
RestAPI: {
Properties: {
DefinitionBody: {
x-amazon-apigateway-binary-media-types: [
"application/octet-stream"
"application/x-tar"
"application/zip"
"audio/basic"
"audio/ogg"
"audio/mp4"
"audio/mpeg"
"audio/wav"
"audio/webm"
"image/png"
"image/jpg"
+ "image/jpeg"
"image/gif"
"video/ogg"
"video/mpeg"
"video/webm"
]
}
}
}
myauthdb6d: {
Properties: {
- Events: {
- }
- Policies: [
- {
- Version: "2012-10-17"
- Statement: [
- {
- Action: [
- "logs:CreateLogGroup"
- "logs:CreateLogStream"
- "logs:PutLogEvents"
- ]
- Resource: "arn:aws:logs:*:*:*"
- Effect: "Allow"
- }
- ]
- }
- ]
+ Policies: {
+ Version: "2012-10-17"
+ Statement: [
+ {
+ Action: [
+ "logs:CreateLogGroup"
+ "logs:CreateLogStream"
+ "logs:PutLogEvents"
+ ]
+ Resource: "arn:aws:logs:*:*:*"
+ Effect: "Allow"
+ }
+ ]
+ }
}
}
APIHandler: {
Properties: {
- Events: {
- indexget6bb1: {
- Type: "Api"
- Properties: {
- Path: "/"
- RestApiId: {
- Ref: "RestAPI"
- }
- Method: "get"
- }
- }
- }
- Policies: [
- {
- Version: "2012-10-17"
- Statement: [
- {
- Action: [
- "logs:CreateLogGroup"
- "logs:CreateLogStream"
- "logs:PutLogEvents"
- ]
- Resource: "arn:aws:logs:*:*:*"
- Effect: "Allow"
- }
- ]
- }
- ]
+ Policies: {
+ Version: "2012-10-17"
+ Statement: [
+ {
+ Action: [
+ "logs:CreateLogGroup"
+ "logs:CreateLogStream"
+ "logs:PutLogEvents"
+ ]
+ Resource: "arn:aws:logs:*:*:*"
+ Effect: "Allow"
+ }
+ ]
+ }
}
}
myauthdb6dInvokePermission: {
Properties: {
+ SourceArn: {
+ Fn::Sub: [
+ "arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${RestAPIId}/*"
+ {
+ RestAPIId: {
+ Ref: "RestAPI"
+ }
+ }
+ ]
+ }
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment