Created
May 21, 2019 20:05
-
-
Save allenmichael/57f8505d956aa2aa275af7697ad2f7ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports.handler = async (event) => { | |
console.log(JSON.stringify(event, 2)); | |
return { | |
statusCode: 200, | |
body: "Echoing your message: " + event.echo | |
} | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
AWSTemplateFormatVersion: '2010-09-09' | |
Transform: AWS::Serverless-2016-10-31 | |
Resources: | |
MyLambdaRouteHandlerFunction: | |
Type: AWS::Serverless::Function | |
Properties: | |
Handler: index.handler | |
Timeout: 30 | |
Runtime: nodejs10.x | |
CodeUri: ./ | |
Policies: | |
- AWSLambdaFullAccess | |
- CloudWatchLogsFullAccess | |
MyWebSocketApi: | |
Type: AWS::ApiGatewayV2::Api | |
Properties: | |
Name: MyWebSocketApiRouteResponse | |
ProtocolType: WEBSOCKET | |
RouteSelectionExpression: "$request.body.action" | |
TestRoute: | |
Type: AWS::ApiGatewayV2::Route | |
Properties: | |
ApiId: !Ref MyWebSocketApi | |
RouteKey: test | |
AuthorizationType: NONE | |
Target: !Join | |
- '/' | |
- - 'integrations' | |
- !Ref TestLambdaIntegration | |
TestLambdaIntegration: | |
Type: AWS::ApiGatewayV2::Integration | |
Properties: | |
ApiId: !Ref MyWebSocketApi | |
Description: Test Integration | |
IntegrationType: AWS_PROXY | |
IntegrationUri: | |
Fn::Sub: | |
arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${MyLambdaRouteHandlerFunction.Arn}/invocations | |
MyRouteResponse: | |
Type: AWS::ApiGatewayV2::RouteResponse | |
Properties: | |
RouteId: !Ref TestRoute | |
ApiId: !Ref MyWebSocketApi | |
RouteResponseKey: $default | |
Deployment: | |
Type: AWS::ApiGatewayV2::Deployment | |
DependsOn: | |
- TestRoute | |
Properties: | |
ApiId: !Ref MyWebSocketApi | |
Stage: | |
Type: AWS::ApiGatewayV2::Stage | |
Properties: | |
StageName: v1 | |
Description: Version 1 'stage' | |
DeploymentId: !Ref Deployment | |
ApiId: !Ref MyWebSocketApi | |
ApiGatewayLambdaInvokePermission: | |
Type: AWS::Lambda::Permission | |
DependsOn: | |
- MyWebSocketApi | |
- MyLambdaRouteHandlerFunction | |
Properties: | |
Action: lambda:InvokeFunction | |
FunctionName: !Ref MyLambdaRouteHandlerFunction | |
Principal: apigateway.amazonaws.com | |
Outputs: | |
MyWebSocketApi: | |
Description: "API Gateway endpoint URL for Prod stage for Hello World function" | |
Value: !Sub "https://${MyWebSocketApi}.execute-api.${AWS::Region}.amazonaws.com/v1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment