Skip to content

Instantly share code, notes, and snippets.

@brianleroux
Created July 13, 2020 17:11
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 brianleroux/0df54b01602303578100745b6df7a87d to your computer and use it in GitHub Desktop.
Save brianleroux/0df54b01602303578100745b6df7a87d to your computer and use it in GitHub Desktop.
{
"AWSTemplateFormatVersion": "2010-09-09",
"Transform": "AWS::Serverless-2016-10-31",
"Description": "Exported by architect/package@2.0.0-RC.0 on 2020-07-13T17:10:57.465Z",
"Resources": {
"HTTP": {
"Type": "AWS::Serverless::HttpApi",
"Properties": {
"StageName": "$default",
"DefinitionBody": {
"openapi": "3.0.1",
"info": {
"title": {
"Ref": "AWS::StackName"
}
},
"paths": {
"/": {
"get": {
"x-amazon-apigateway-integration": {
"payloadFormatVersion": "2.0",
"type": "aws_proxy",
"httpMethod": "POST",
"uri": {
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetIndex.Arn}/invocations"
},
"connectionType": "INTERNET"
}
}
},
"/login": {
"get": {
"x-amazon-apigateway-integration": {
"payloadFormatVersion": "2.0",
"type": "aws_proxy",
"httpMethod": "POST",
"uri": {
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetLogin.Arn}/invocations"
},
"connectionType": "INTERNET"
}
}
},
"/$default": {
"x-amazon-apigateway-any-method": {
"isDefaultRoute": true,
"x-amazon-apigateway-integration": {
"payloadFormatVersion": "2.0",
"type": "aws_proxy",
"httpMethod": "POST",
"uri": {
"Fn::Sub": "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${GetIndex.Arn}/invocations"
},
"connectionType": "INTERNET"
}
}
},
"/_static/{proxy+}": {
"get": {
"x-amazon-apigateway-integration": {
"payloadFormatVersion": "1.0",
"type": "http_proxy",
"httpMethod": "GET",
"uri": {
"Fn::Sub": [
"http://${bukkit}.s3.${AWS::Region}.amazonaws.com/{proxy}",
{
"bukkit": {
"Ref": "StaticBucket"
}
}
]
},
"connectionType": "INTERNET",
"timeoutInMillis": 30000,
"requestParameters": {
"integration.request.path.proxy": "method.request.path.proxy"
}
}
}
}
}
}
}
},
"GetIndex": {
"Type": "AWS::Serverless::Function",
"Properties": {
"Handler": "index.handler",
"CodeUri": "./src/http/get-index",
"Runtime": "nodejs12.x",
"MemorySize": 1152,
"Timeout": 5,
"Environment": {
"Variables": {
"ARC_ROLE": {
"Ref": "Role"
},
"ARC_CLOUDFORMATION": {
"Ref": "AWS::StackName"
},
"ARC_APP_NAME": "ws-fun",
"ARC_HTTP": "aws_proxy",
"NODE_ENV": "staging",
"SESSION_TABLE_NAME": "jwe",
"ARC_WSS_URL": {
"Fn::Sub": [
"wss://${WS}.execute-api.${AWS::Region}.amazonaws.com/staging",
{}
]
}
}
},
"Role": {
"Fn::Sub": [
"arn:aws:iam::${AWS::AccountId}:role/${roleName}",
{
"roleName": {
"Ref": "Role"
}
}
]
},
"Events": {
"GetIndexEvent": {
"Type": "HttpApi",
"Properties": {
"Path": "/",
"Method": "GET",
"ApiId": {
"Ref": "HTTP"
}
}
}
}
}
},
"GetLogin": {
"Type": "AWS::Serverless::Function",
"Properties": {
"Handler": "index.handler",
"CodeUri": "./src/http/get-login",
"Runtime": "nodejs12.x",
"MemorySize": 1152,
"Timeout": 5,
"Environment": {
"Variables": {
"ARC_ROLE": {
"Ref": "Role"
},
"ARC_CLOUDFORMATION": {
"Ref": "AWS::StackName"
},
"ARC_APP_NAME": "ws-fun",
"ARC_HTTP": "aws_proxy",
"NODE_ENV": "staging",
"SESSION_TABLE_NAME": "jwe",
"ARC_WSS_URL": {
"Fn::Sub": [
"wss://${WS}.execute-api.${AWS::Region}.amazonaws.com/staging",
{}
]
}
}
},
"Role": {
"Fn::Sub": [
"arn:aws:iam::${AWS::AccountId}:role/${roleName}",
{
"roleName": {
"Ref": "Role"
}
}
]
},
"Events": {
"GetLoginEvent": {
"Type": "HttpApi",
"Properties": {
"Path": "/login",
"Method": "GET",
"ApiId": {
"Ref": "HTTP"
}
}
}
}
}
},
"InvokeDefaultPermission": {
"Type": "AWS::Lambda::Permission",
"Properties": {
"FunctionName": {
"Ref": "GetIndex"
},
"Action": "lambda:InvokeFunction",
"Principal": "apigateway.amazonaws.com",
"SourceArn": {
"Fn::Sub": [
"arn:aws:execute-api:${AWS::Region}:${AWS::AccountId}:${ApiId}/*/*",
{
"ApiId": {
"Ref": "HTTP"
}
}
]
}
}
},
"StaticBucket": {
"Type": "AWS::S3::Bucket",
"Properties": {
"AccessControl": "PublicRead",
"WebsiteConfiguration": {
"IndexDocument": "index.html",
"ErrorDocument": "404.html"
}
}
},
"WS": {
"Type": "AWS::ApiGatewayV2::Api",
"Properties": {
"Name": "WsFunWebsocket",
"ProtocolType": "WEBSOCKET",
"RouteSelectionExpression": "$request.body.message"
}
},
"WebsocketDeployment": {
"Type": "AWS::ApiGatewayV2::Deployment",
"DependsOn": [
"WebsocketConnectRoute",
"WebsocketDefaultRoute",
"WebsocketDisconnectRoute"
],
"Properties": {
"ApiId": {
"Ref": "WS"
}
}
},
"WebsocketStage": {
"Type": "AWS::ApiGatewayV2::Stage",
"Properties": {
"StageName": "staging",
"DeploymentId": {
"Ref": "WebsocketDeployment"
},
"ApiId": {
"Ref": "WS"
}
}
},
"WebSocketPolicy": {
"Type": "AWS::IAM::Policy",
"DependsOn": "Role",
"Properties": {
"PolicyName": "ArcWebSocketPolicy",
"PolicyDocument": {
"Statement": [
{
"Effect": "Allow",
"Action": [
"execute-api:Invoke",
"execute-api:ManageConnections"
],
"Resource": [
{
"Fn::Sub": [
"arn:aws:execute-api:${AWS::Region}:*:${api}/*",
{
"api": {
"Ref": "WS"
}
}
]
}
]
}
]
},
"Roles": [
{
"Ref": "Role"
}
]
}
},
"WebsocketDefault": {
"Type": "AWS::Serverless::Function",
"Properties": {
"Handler": "index.handler",
"CodeUri": "./src/ws/default",
"Runtime": "nodejs12.x",
"MemorySize": 1152,
"Timeout": 5,
"Environment": {
"Variables": {
"ARC_ROLE": {
"Ref": "Role"
},
"ARC_CLOUDFORMATION": {
"Ref": "AWS::StackName"
},
"ARC_APP_NAME": "ws-fun",
"ARC_HTTP": "aws_proxy",
"NODE_ENV": "staging",
"SESSION_TABLE_NAME": "jwe",
"ARC_WSS_URL": {
"Fn::Sub": [
"wss://${WS}.execute-api.${AWS::Region}.amazonaws.com/staging",
{}
]
}
}
},
"Role": {
"Fn::Sub": [
"arn:aws:iam::${AWS::AccountId}:role/${roleName}",
{
"roleName": {
"Ref": "Role"
}
}
]
},
"Events": {}
}
},
"WebsocketDefaultRoute": {
"Type": "AWS::ApiGatewayV2::Route",
"Properties": {
"ApiId": {
"Ref": "WS"
},
"RouteKey": "$default",
"OperationName": "WebsocketDefaultRoute",
"Target": {
"Fn::Join": [
"/",
[
"integrations",
{
"Ref": "WebsocketDefaultIntegration"
}
]
]
}
}
},
"WebsocketDefaultIntegration": {
"Type": "AWS::ApiGatewayV2::Integration",
"Properties": {
"ApiId": {
"Ref": "WS"
},
"IntegrationType": "AWS_PROXY",
"IntegrationUri": {
"Fn::Sub": [
"arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${WebsocketDefault.Arn}/invocations",
{}
]
}
}
},
"WebsocketDefaultPermission": {
"Type": "AWS::Lambda::Permission",
"DependsOn": [
"WS",
"WebsocketDefault"
],
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "WebsocketDefault"
},
"Principal": "apigateway.amazonaws.com"
}
},
"WebsocketConnect": {
"Type": "AWS::Serverless::Function",
"Properties": {
"Handler": "index.handler",
"CodeUri": "./src/ws/connect",
"Runtime": "nodejs12.x",
"MemorySize": 1152,
"Timeout": 5,
"Environment": {
"Variables": {
"ARC_ROLE": {
"Ref": "Role"
},
"ARC_CLOUDFORMATION": {
"Ref": "AWS::StackName"
},
"ARC_APP_NAME": "ws-fun",
"ARC_HTTP": "aws_proxy",
"NODE_ENV": "staging",
"SESSION_TABLE_NAME": "jwe",
"ARC_WSS_URL": {
"Fn::Sub": [
"wss://${WS}.execute-api.${AWS::Region}.amazonaws.com/staging",
{}
]
}
}
},
"Role": {
"Fn::Sub": [
"arn:aws:iam::${AWS::AccountId}:role/${roleName}",
{
"roleName": {
"Ref": "Role"
}
}
]
},
"Events": {}
}
},
"WebsocketConnectRoute": {
"Type": "AWS::ApiGatewayV2::Route",
"Properties": {
"ApiId": {
"Ref": "WS"
},
"RouteKey": "$connect",
"OperationName": "WebsocketConnectRoute",
"Target": {
"Fn::Join": [
"/",
[
"integrations",
{
"Ref": "WebsocketConnectIntegration"
}
]
]
}
}
},
"WebsocketConnectIntegration": {
"Type": "AWS::ApiGatewayV2::Integration",
"Properties": {
"ApiId": {
"Ref": "WS"
},
"IntegrationType": "AWS_PROXY",
"IntegrationUri": {
"Fn::Sub": [
"arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${WebsocketConnect.Arn}/invocations",
{}
]
}
}
},
"WebsocketConnectPermission": {
"Type": "AWS::Lambda::Permission",
"DependsOn": [
"WS",
"WebsocketConnect"
],
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "WebsocketConnect"
},
"Principal": "apigateway.amazonaws.com"
}
},
"WebsocketDisconnect": {
"Type": "AWS::Serverless::Function",
"Properties": {
"Handler": "index.handler",
"CodeUri": "./src/ws/disconnect",
"Runtime": "nodejs12.x",
"MemorySize": 1152,
"Timeout": 5,
"Environment": {
"Variables": {
"ARC_ROLE": {
"Ref": "Role"
},
"ARC_CLOUDFORMATION": {
"Ref": "AWS::StackName"
},
"ARC_APP_NAME": "ws-fun",
"ARC_HTTP": "aws_proxy",
"NODE_ENV": "staging",
"SESSION_TABLE_NAME": "jwe",
"ARC_WSS_URL": {
"Fn::Sub": [
"wss://${WS}.execute-api.${AWS::Region}.amazonaws.com/staging",
{}
]
}
}
},
"Role": {
"Fn::Sub": [
"arn:aws:iam::${AWS::AccountId}:role/${roleName}",
{
"roleName": {
"Ref": "Role"
}
}
]
},
"Events": {}
}
},
"WebsocketDisconnectRoute": {
"Type": "AWS::ApiGatewayV2::Route",
"Properties": {
"ApiId": {
"Ref": "WS"
},
"RouteKey": "$disconnect",
"OperationName": "WebsocketDisconnectRoute",
"Target": {
"Fn::Join": [
"/",
[
"integrations",
{
"Ref": "WebsocketDisconnectIntegration"
}
]
]
}
}
},
"WebsocketDisconnectIntegration": {
"Type": "AWS::ApiGatewayV2::Integration",
"Properties": {
"ApiId": {
"Ref": "WS"
},
"IntegrationType": "AWS_PROXY",
"IntegrationUri": {
"Fn::Sub": [
"arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${WebsocketDisconnect.Arn}/invocations",
{}
]
}
}
},
"WebsocketDisconnectPermission": {
"Type": "AWS::Lambda::Permission",
"DependsOn": [
"WS",
"WebsocketDisconnect"
],
"Properties": {
"Action": "lambda:InvokeFunction",
"FunctionName": {
"Ref": "WebsocketDisconnect"
},
"Principal": "apigateway.amazonaws.com"
}
},
"Role": {
"Type": "AWS::IAM::Role",
"Properties": {
"AssumeRolePolicyDocument": {
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "lambda.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
},
"Policies": [
{
"PolicyName": "ArcGlobalPolicy",
"PolicyDocument": {
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:DescribeLogStreams"
],
"Resource": "arn:aws:logs:*:*:*"
}
]
}
}
]
}
}
},
"Outputs": {
"API": {
"Description": "API Gateway (HTTP)",
"Value": {
"Fn::Sub": [
"https://${ApiId}.execute-api.${AWS::Region}.amazonaws.com",
{
"ApiId": {
"Ref": "HTTP"
}
}
]
}
},
"ApiId": {
"Description": "API ID (ApiId)",
"Value": {
"Ref": "HTTP"
}
},
"BucketURL": {
"Description": "Bucket URL",
"Value": {
"Fn::Sub": [
"http://${bukkit}.s3-website-${AWS::Region}.amazonaws.com",
{
"bukkit": {
"Ref": "StaticBucket"
}
}
]
}
},
"WSS": {
"Description": "Websocket Endpoint",
"Value": {
"Fn::Sub": [
"wss://${WS}.execute-api.${AWS::Region}.amazonaws.com/staging",
{}
]
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment