Skip to content
This repository was archived by the owner on Oct 9, 2021. It is now read-only.

Commit 41a5d6b

Browse files
committed
v2.0.0 Release
Major version release to address updates/issues identified in CHANGELOG.
1 parent 1dde27e commit 41a5d6b

File tree

8 files changed

+476
-337
lines changed

8 files changed

+476
-337
lines changed

CHANGELOG.md

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=========
2+
CHANGELOG
3+
=========
4+
5+
2.0.0
6+
=====
7+
* Introduces multi-region stack support for workshop to run in any of the 5 existing regions that have API Gateway and Lambda.
8+
* Solves hardcoded attribute dependencies, allowing for multiple stacks to run simultaneously in the same AWS account. Resources are created with stack name prepended to the resource names.
9+
* Removes caching from API Gateway stage to reduce costs for long running stacks.
10+
11+
1.0.0
12+
==========
13+
* All commits prior to release 2.0.0 are considered a part of v1.0.0 release.
14+
* Initial release on Github.
15+
* Provides baseline zombie survivor chat application via CloudFormation stack, Lambda functions, DynamoDB tables, and API Gateway resources.

ChatServiceLambdaFunctions/ZombieGetMessages.js

+17-7
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,34 @@
11
console.log('Loading function');
22
var aws = require('aws-sdk');
3-
var ddb = new aws.DynamoDB(
4-
{region: "us-west-2",
5-
params: {TableName: "messages"}});
6-
3+
var ddb;
4+
75
var theContext;
86

97
function dynamoCallback(err, response) {
10-
if (err) {
8+
if (err) {
119
console.log('error' + err, err.stack); // an error occurred
1210
theContext.fail(err);
1311
}
14-
12+
1513
else {
16-
console.log('result: ' + JSON.stringify(response)) // successful response
14+
console.log('result: ' + JSON.stringify(response)) // successful response
1715
theContext.succeed(response);
1816
}
1917
}
2018

19+
function init(context) {
20+
if(!ddb) {
21+
var stackName = context.functionName.split('-z0mb1es-')[0];
22+
var stackRegion = context.functionName.split('-GetMessagesFromDynamoDB-')[1];
23+
ddb = new aws.DynamoDB({
24+
region: stackRegion,
25+
params: { TableName: stackName + "-messages" }
26+
});
27+
}
28+
}
29+
2130
exports.handler = function(event, context) {
31+
init(context);
2232
theContext = context;
2333
var params = {
2434
"KeyConditions": {

ChatServiceLambdaFunctions/ZombiePostMessage.js

+19-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Processes incoming messages for Zombie chat service
22
var aws = require('aws-sdk');
3-
var ddb = new aws.DynamoDB(
4-
{region: "us-west-2",
5-
params: {TableName: "messages"}}
6-
);
3+
var ddb;
74
var querystring = require('querystring');
85

96
var theContext;
@@ -16,20 +13,21 @@ var channel = 'default';
1613

1714

1815
exports.handler = function(event, context) {
16+
init(context);
1917
theContext = context;
20-
18+
2119
if(event.message == null || event.message == 'null' || event.name == null || event.name == 'null') {
22-
return context.fail("Message and Name cannot be null");
20+
return context.fail("Message and Name cannot be null");
2321
} else {
2422
message = event.message;
2523
from = event.name;
2624
}
27-
25+
2826
if (event.timestamp == null || event.timestamp == 'null') {
2927
event.timestamp = "" + new Date().getTime();
3028
timestamp = event.timestamp;
3129
}
32-
30+
3331
/**
3432
* For Debubugging input params to the lambda function
3533
console.log('Message: ' + message);
@@ -45,10 +43,22 @@ exports.handler = function(event, context) {
4543
"name":{"S":from}
4644
}
4745
};
48-
46+
4947
dynamoPut(DDBparams);
5048
};
5149

50+
function init(context) {
51+
if(!ddb) {
52+
console.log("Initializing DynamoDB client.");
53+
var stackName = context.functionName.split('-z0mb1es-')[0];
54+
var stackRegion = context.functionName.split('-WriteMessagesToDynamoDB-')[1];
55+
ddb = new aws.DynamoDB({
56+
region: stackRegion,
57+
params: { TableName: stackName + "-messages" }
58+
});
59+
}
60+
}
61+
5262
function dynamoPut(params){
5363
console.log("Putting item into DynamoDB");
5464
ddb.putItem(params, dynamoCallback);

0 commit comments

Comments
 (0)