Skip to content

Instantly share code, notes, and snippets.

@rosskarchner
Created October 30, 2018 15:47
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 rosskarchner/6e208c870b1fcfc4f9a6f3746e1f8f61 to your computer and use it in GitHub Desktop.
Save rosskarchner/6e208c870b1fcfc4f9a6f3746e1f8f61 to your computer and use it in GitHub Desktop.
SAM hello world, before and after processing into plain Cloudformation
AWSTemplateFormatVersion: 2010-09-09
Outputs:
HelloWorldApi:
Description: API Gateway endpoint URL for Prod stage for Hello World function
Value: !Sub >-
https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/
HelloWorldFunctionIamRole:
Description: Implicit IAM Role created for Hello World function
Value: !GetAtt
- HelloWorldFunctionRole
- Arn
HelloWorldFunction:
Description: Hello World Lambda Function ARN
Value: !GetAtt
- HelloWorldFunction
- Arn
Description: |
hello-sam
Sample SAM Template for hello-sam
Resources:
HelloWorldFunctionHelloWorldPermissionProd:
Type: 'AWS::Lambda::Permission'
Properties:
Action: 'lambda:invokeFunction'
Principal: apigateway.amazonaws.com
FunctionName: !Ref HelloWorldFunction
SourceArn: !Sub
- >-
arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/hello
- __Stage__: Prod
__ApiId__: !Ref ServerlessRestApi
HelloWorldFunctionRole:
Type: 'AWS::IAM::Role'
Properties:
ManagedPolicyArns:
- 'arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole'
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Action:
- 'sts:AssumeRole'
Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
ServerlessRestApiProdStage:
Type: 'AWS::ApiGateway::Stage'
Properties:
DeploymentId: !Ref ServerlessRestApiDeployment47fc2d5f9d
RestApiId: !Ref ServerlessRestApi
StageName: Prod
ServerlessRestApiDeployment47fc2d5f9d:
Type: 'AWS::ApiGateway::Deployment'
Properties:
RestApiId: !Ref ServerlessRestApi
Description: 'RestApi deployment id: 47fc2d5f9d21ad56f83937abe2779d0e26d7095e'
StageName: Stage
HelloWorldFunctionHelloWorldPermissionTest:
Type: 'AWS::Lambda::Permission'
Properties:
Action: 'lambda:invokeFunction'
Principal: apigateway.amazonaws.com
FunctionName: !Ref HelloWorldFunction
SourceArn: !Sub
- >-
arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${__ApiId__}/${__Stage__}/GET/hello
- __Stage__: '*'
__ApiId__: !Ref ServerlessRestApi
ServerlessRestApi:
Type: 'AWS::ApiGateway::RestApi'
Properties:
Body:
info:
version: '1.0'
title: !Ref 'AWS::StackName'
paths:
/hello:
get:
x-amazon-apigateway-integration:
httpMethod: POST
type: aws_proxy
uri: !Sub >-
arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HelloWorldFunction.Arn}/invocations
responses: {}
swagger: '2.0'
HelloWorldFunction:
Type: 'AWS::Lambda::Function'
Properties:
Code:
S3Bucket: temporaryross8
S3Key: fe9a003d8453352d99b99fc958e64e3b
Tags:
- Value: SAM
Key: 'lambda:createdBy'
Environment:
Variables:
PARAM1: VALUE
Handler: app.lambda_handler
Role: !GetAtt
- HelloWorldFunctionRole
- Arn
Timeout: 3
Runtime: python3.6
AWSTemplateFormatVersion: '2010-09-09'
Description: 'hello-sam
Sample SAM Template for hello-sam
'
Globals:
Function:
Timeout: 3
Outputs:
HelloWorldApi:
Description: API Gateway endpoint URL for Prod stage for Hello World function
Value:
Fn::Sub: https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/
HelloWorldFunction:
Description: Hello World Lambda Function ARN
Value:
Fn::GetAtt:
- HelloWorldFunction
- Arn
HelloWorldFunctionIamRole:
Description: Implicit IAM Role created for Hello World function
Value:
Fn::GetAtt:
- HelloWorldFunctionRole
- Arn
Resources:
HelloWorldFunction:
Properties:
CodeUri: s3://temporaryross8/fe9a003d8453352d99b99fc958e64e3b
Environment:
Variables:
PARAM1: VALUE
Events:
HelloWorld:
Properties:
Method: get
Path: /hello
Type: Api
Handler: app.lambda_handler
Runtime: python3.6
Type: AWS::Serverless::Function
Transform: AWS::Serverless-2016-10-31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment