Skip to content

Commit 8eab81c

Browse files
authored
Merge pull request #199 from rncain/master
Fixing issues when creating tables
2 parents 131ad0d + 5815188 commit 8eab81c

File tree

2 files changed

+61
-37
lines changed

2 files changed

+61
-37
lines changed

common.js

Lines changed: 59 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
http://aws.amazon.com/asl/
77
8-
or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and limitations under the License.
8+
or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and limitations under the License.
99
*/
1010

1111
var async = require('async');
@@ -81,7 +81,10 @@ exports.createTables = function (dynamoDB, callback) {
8181
KeyType: 'HASH'
8282
}],
8383
TableName: filesTable,
84-
BillingMode: "PAY_PER_REQUEST"
84+
ProvisionedThroughput: {
85+
ReadCapacityUnits: 1,
86+
WriteCapacityUnits: 5
87+
}
8588
};
8689
var configKey = s3prefix;
8790
var configSpec = {
@@ -94,7 +97,10 @@ exports.createTables = function (dynamoDB, callback) {
9497
KeyType: 'HASH'
9598
}],
9699
TableName: configTable,
97-
BillingMode: "PAY_PER_REQUEST"
100+
ProvisionedThroughput: {
101+
ReadCapacityUnits: 1,
102+
WriteCapacityUnits: 5
103+
}
98104
};
99105

100106
var batchKey = batchId;
@@ -121,7 +127,10 @@ exports.createTables = function (dynamoDB, callback) {
121127
KeyType: 'RANGE'
122128
}],
123129
TableName: batchTable,
124-
BillingMode: "PAY_PER_REQUEST",
130+
ProvisionedThroughput: {
131+
ReadCapacityUnits: 1,
132+
WriteCapacityUnits: 5
133+
},
125134
GlobalSecondaryIndexes: [{
126135
IndexName: batchStatusGSI,
127136
KeySchema: [{
@@ -502,21 +511,6 @@ exports.createS3EventSource = function (s3, lambda, bucket, prefix, functionName
502511
if (err) {
503512
callback(err);
504513
} else {
505-
// now create the event source mapping
506-
var newEventConfiguration = {
507-
Events: ['s3:ObjectCreated:*',],
508-
LambdaFunctionArn: functionArn,
509-
Filter: {
510-
Key: {
511-
FilterRules: [{
512-
Name: 'prefix',
513-
Value: prefix + "/"
514-
}]
515-
}
516-
},
517-
Id: "LambdaRedshiftLoaderEventSource-" + uuid.v4()
518-
};
519-
520514
// add the notification configuration to the
521515
// set of existing lambda configurations
522516
if (!currentNotificationConfiguration) {
@@ -526,24 +520,54 @@ exports.createS3EventSource = function (s3, lambda, bucket, prefix, functionName
526520
currentNotificationConfiguration.LambdaFunctionConfigurations = [];
527521
}
528522

529-
currentNotificationConfiguration.LambdaFunctionConfigurations.push(newEventConfiguration);
530-
531-
// push the function event trigger
532-
// configurations back into S3
533-
var params = {
534-
Bucket: bucket,
535-
NotificationConfiguration: currentNotificationConfiguration
536-
};
537-
538-
s3.putBucketNotificationConfiguration(params, function (err, data) {
539-
if (err) {
540-
console.log(this.httpResponse.body.toString());
541-
console.log(err);
542-
callback(err);
543-
} else {
544-
callback();
523+
configAlreadyExists = false;
524+
525+
// Let's check our configs to see if we already have one that exists
526+
currentNotificationConfiguration.LambdaFunctionConfigurations.forEach(config => {
527+
if (config.Filter.Key.FilterRules[0].Value == prefix + '/') {
528+
console.log('Skipping creation of notification config because it already exists');
529+
configAlreadyExists = true;
545530
}
546531
});
532+
533+
// Create a new notification config
534+
if (!configAlreadyExists) {
535+
console.log('Creating notification configuration');
536+
537+
// now create the event source mapping
538+
var newEventConfiguration = {
539+
Events: ['s3:ObjectCreated:*',],
540+
LambdaFunctionArn: functionArn,
541+
Filter: {
542+
Key: {
543+
FilterRules: [{
544+
Name: 'prefix',
545+
Value: prefix + "/"
546+
}]
547+
}
548+
},
549+
Id: "LambdaRedshiftLoaderEventSource-" + uuid.v4()
550+
};
551+
552+
currentNotificationConfiguration.LambdaFunctionConfigurations.push(newEventConfiguration);
553+
554+
// push the function event trigger
555+
// configurations back into S3
556+
var params = {
557+
Bucket: bucket,
558+
NotificationConfiguration: currentNotificationConfiguration
559+
};
560+
561+
s3.putBucketNotificationConfiguration(params, function (err, data) {
562+
if (err) {
563+
console.log(this.httpResponse.body.toString());
564+
console.log(err);
565+
callback(err);
566+
} else {
567+
callback();
568+
}
569+
});
570+
}
547571
}
548572
});
549573
}

index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
66
http://aws.amazon.com/asl/
77
8-
or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and limitations under the License.
8+
or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions and limitations under the License.
99
*/
10-
var debug = process.env['DEBUG'] || false;
10+
var debug = process.env['DEBUG'] !== undefined
1111
var pjson = require('./package.json');
1212
var region = process.env['AWS_REGION'];
1313

0 commit comments

Comments
 (0)