Skip to content

Instantly share code, notes, and snippets.

@tehzwen
Created March 24, 2020 22:34
Show Gist options
  • Save tehzwen/6149d668fd83d688a711b1a77ea86ad2 to your computer and use it in GitHub Desktop.
Save tehzwen/6149d668fd83d688a711b1a77ea86ad2 to your computer and use it in GitHub Desktop.
AWS cfn template for serverless
Resources:
ZachLambdaRole:
Type: AWS::IAM::Role
Properties:
Description: Lambda execution role for Zach
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
ManagedPolicyArns:
- arn:aws:iam::aws:policy/service-role/AWSLambdaBasicExecutionRole
PrivateS3Bucket:
Type: AWS::S3::Bucket
Properties:
AccessControl: Private
BucketName: zachserverlessappbucket
ApiGateway:
Type: AWS::ApiGatewayV2::Api
Properties:
Description: An api for testing lambda functions with s3
Name: zachsserverlessapi
ProtocolType: HTTP
MyLambdaFunction:
Type: AWS::Lambda::Function
Properties:
Runtime: nodejs12.x
Role: !GetAtt ZachLambdaRole.Arn
Handler: index.handler
Code:
ZipFile: |
var aws = require('aws-sdk')
exports.handler = function(event, context, cb) {
cb(null, {"val":"0"})
}
Description: Test function used for this stack
MainRouteIntegration:
Type: AWS::ApiGatewayV2::Integration
DependsOn:
- ApiGateway
Properties:
ApiId: !Ref ApiGateway
Description: Lambda Integration for main route
IntegrationType: AWS_PROXY
IntegrationUri: !GetAtt MyLambdaFunction.Arn
IntegrationMethod: GET
PayloadFormatVersion: '2.0'
ConnectionType: INTERNET
MainRoute:
Type: AWS::ApiGatewayV2::Route
DependsOn:
- ApiGateway
- MyLambdaFunction
- MainRouteIntegration
Properties:
ApiId: !Ref ApiGateway
RouteKey: GET /home
Target: !Join
- /
- - integrations
- !Ref MainRouteIntegration
MainRouteDeployment:
Type: AWS::ApiGatewayV2::Deployment
DependsOn:
- ApiGateway
- MainRoute
- MainStage
Properties:
Description: Main deployment for serverless api
ApiId: !Ref ApiGateway
StageName: Test
MainStage:
Type: AWS::ApiGatewayV2::Stage
DependsOn:
- ApiGateway
- MainRoute
Properties:
ApiId: !Ref ApiGateway
StageName: Test
Description: Test Stage for serverless api
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment