{ "AWSTemplateFormatVersion": "2010-09-09", "Description": "Creates DynamoDB tables, Lambda Functions, and associated IAM roles for the AWS SDK for Unity Chess Game sample. **WARNING** This template creates AWS Resource that you may be billed for.", "Resources": { "ChessMatches": { "Type": "AWS::DynamoDB::Table", "Properties": { "TableName": "ChessMatches", "AttributeDefinitions": [ { "AttributeName": "MatchId", "AttributeType": "S" }, { "AttributeName": "BlackPlayerId", "AttributeType": "S" }, { "AttributeName": "WhitePlayerId", "AttributeType": "S" } ], "KeySchema": [ { "AttributeName": "MatchId", "KeyType": "HASH" } ], "ProvisionedThroughput": { "ReadCapacityUnits": 1, "WriteCapacityUnits": 1 }, "GlobalSecondaryIndexes": [ { "IndexName": "BlackPlayerId-index", "KeySchema": [ { "AttributeName": "BlackPlayerId", "KeyType": "HASH" } ], "Projection": { "ProjectionType": "KEYS_ONLY" }, "ProvisionedThroughput": { "ReadCapacityUnits": 1, "WriteCapacityUnits": 1 } }, { "IndexName": "WhitePlayerId-index", "KeySchema": [ { "AttributeName": "WhitePlayerId", "KeyType": "HASH" } ], "Projection": { "ProjectionType": "KEYS_ONLY" }, "ProvisionedThroughput": { "ReadCapacityUnits": 1, "WriteCapacityUnits": 1 } } ] }, "Metadata": { "AWS::CloudFormation::Designer": { "id": "770691c3-e9a9-48de-bbca-528301edb520" } } }, "ChessPlayers": { "Type": "AWS::DynamoDB::Table", "Properties": { "TableName": "ChessPlayers", "AttributeDefinitions": [ { "AttributeName": "Id", "AttributeType": "S" } ], "KeySchema": [ { "AttributeName": "Id", "KeyType": "HASH" } ], "ProvisionedThroughput": { "ReadCapacityUnits": 1, "WriteCapacityUnits": 1 } }, "Metadata": { "AWS::CloudFormation::Designer": { "id": "62784747-69cb-4d15-9724-3f70a6c55593" } } }, "SNSEndpointLookup": { "Type": "AWS::DynamoDB::Table", "Properties": { "TableName": "SNSEndpointLookup", "AttributeDefinitions": [ { "AttributeName": "SNSEndpointARN", "AttributeType": "S" }, { "AttributeName": "PlayerId", "AttributeType": "S" } ], "KeySchema": [ { "AttributeName": "PlayerId", "KeyType": "HASH" }, { "AttributeName": "SNSEndpointARN", "KeyType": "RANGE" } ], "ProvisionedThroughput": { "ReadCapacityUnits": 1, "WriteCapacityUnits": 1 } }, "Metadata": { "AWS::CloudFormation::Designer": { "id": "656f4e0d-77ed-453e-9126-ddbf2e7f8978" } } }, "NewChessMatch": { "Type": "AWS::Lambda::Function", "Properties": { "Handler": "index.handler", "Role": { "Fn::GetAtt": [ "NewChessMatchExecutionRole", "Arn" ] }, "Code": { "ZipFile": "function checkMatchId(e,a,n,t){var I=e+a,c={TableName:TABLE_NAME,Key:{MatchId:I}};dynamo.getItem(c,function(c,o){c?n.fail(c):Object.keys(o).length>0?checkMatchId(e,a+1,n,t):t(I)})}console.log('Loading function');var TABLE_NAME='ChessMatches',INITIAL_FEN='rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1',INITIAL_LONG_ALG_NOTATION=' ',doc=require('dynamodb-doc'),dynamo=new doc.DynamoDB();exports.handler=function(e,a){var n=e.requesterId,t=e.opponentId;n&&t||a.fail('Must provide requesterId and opponentId');var I,c;Math.random()<.5?(I=n,c=t):(I=t,c=n);var o=I+c,d=function(e){dynamo.putItem({TableName:TABLE_NAME,Item:{MatchId:e,BlackPlayerId:I,WhitePlayerId:c,FEN:INITIAL_FEN,AlgebraicNotation:INITIAL_LONG_ALG_NOTATION}},function(n){n?a.fail(n):a.succeed(e)})};checkMatchId(o,0,a,d)};" }, "Runtime": "nodejs", "Timeout": "25" }, "Metadata": { "AWS::CloudFormation::Designer": { "id": "3c8126e7-61a5-4a7a-85c2-81a52cb80b5c" } }, "DependsOn": [ "NewChessMatchExecutionRole" ] }, "NewChessMatchExecutionRole": { "Type": "AWS::IAM::Role", "Properties": { "AssumeRolePolicyDocument": { "Version": "2012-10-17", "Statement": [ { "Effect": "Allow", "Principal": { "Service": [ "lambda.amazonaws.com" ] }, "Action": [ "sts:AssumeRole" ] } ] }, "Policies": [ { "PolicyName": "NewChessMatchRole", "PolicyDocument": { "Version": "2012-10-17", "Statement": [ { "Action": [ "dynamodb:DeleteItem", "dynamodb:GetItem", "dynamodb:PutItem", "dynamodb:Query", "dynamodb:Scan", "dynamodb:UpdateItem" ], "Effect": "Allow", "Resource": "*" }, { "Resource": "*", "Action": [ "logs:CreateLogGroup", "logs:CreateLogStream", "logs:PutLogEvents" ], "Effect": "Allow" } ] } } ] }, "Metadata": { "AWS::CloudFormation::Designer": { "id": "76004226-5748-4867-993e-8982c2c8ec6d" } } }, "NewMoveNotifier": { "Type": "AWS::Lambda::Function", "Properties": { "Handler": "index.handler", "Role": { "Fn::GetAtt": [ "NewMoveNotifierExecutionRole", "Arn" ] }, "Code": { "ZipFile": { "Fn::Join": [ "", [ "var AWS=require('aws-sdk');console.log('Loading event'),exports.handler=function(e,o){function r(e,o){if(e)recordProcessed(e);else{var r=new AWS.SNS({region:n}),t=o.Items.length;if(0===t)s(null);else{var a=function(e,o){e&&console.log(o),t--,0===t&&s(null)},d=JSON.stringify({'default':'It is now your turn in a chess match!',APNS_SANDBOX:{aps:{alert:'It is now your turn in a chess match!'}}});for(i=0;i