Skip to content

Commit 156f81f

Browse files
author
joshuat
committed
Rewrite to remove sensitive files. Adding script for baking. Adding readme. Making changes for x-account permissions
Allowing the app to be packaged with custom env config Renaming config files to be more forms specific Naming packages does nothing for lambda Updating readme to reflect addition config + scripts improvements to powershell script Add a canned ACL for the S3 upload to that we don't have permission issues cross-account. Remove baked config. Add ACL permission. Alter package script
1 parent b3af446 commit 156f81f

File tree

6 files changed

+50
-8
lines changed

6 files changed

+50
-8
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
node_modules
22
.DS_Store
3+
package
4+
LambdaFunction.zip

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ Managing table redundancy and backups involves many moving parts. Please read [D
1616

1717
[dynamodb-replicator](https://github.com/mapbox/dynamodb-replicator) provides several CLI tools to help manage your DynamoDB table.
1818

19+
### Config and Packaging
20+
21+
For windows users: a powershell script is available to packing the lambda function with all the packages it needs.
22+
23+
```
24+
> npm install
25+
> .\package.ps1
26+
1927
### diff-record
2028
2129
Given two tables and an item's key, this script looks up the record in both tables and checks for consistency.

backup.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ module.exports = function(config, context, done) {
4646
s3.upload({
4747
Bucket: config.backup.bucket,
4848
Key: key,
49-
Body: data
49+
Body: data,
50+
ACL: 'bucket-owner-full-control'
5051
}, function(err) {
5152
if (err) return next(err);
5253
log('[segment %s] Uploaded dynamo backup to s3://%s/%s', index, config.backup.bucket, key);

index.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,6 @@ module.exports.streambotReplicate = streambot(replicate);
99
module.exports.backup = incrementalBackup;
1010
module.exports.streambotBackup = streambot(incrementalBackup);
1111

12-
// process.env.BackupBucket = 'dynamo-incremental-backups'
13-
// process.env.BackupPrefix = 'forms.blue'
14-
// process.env.MultiTenancyColumn = 'InstanceId'
15-
//process.env.PlainTextKeyAsFilename = true;
16-
1712
function replicate(event, context, callback) {
1813
var replicaConfig = {
1914
table: process.env.ReplicaTable,
@@ -174,7 +169,11 @@ function incrementalBackup(event, context, callback) {
174169
};
175170

176171
var req = change.eventName === 'REMOVE' ? 'deleteObject' : 'putObject';
177-
if (req === 'putObject') params.Body = JSON.stringify(change.dynamodb.NewImage);
172+
173+
if (req === 'putObject') {
174+
params.Body = JSON.stringify(change.dynamodb.NewImage);
175+
params.ACL = 'bucket-owner-full-control';
176+
}
178177

179178
s3[req](params, function(err) {
180179
if (err) console.log(

package.ps1

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Write-Output "Packaging Lambda app"
2+
if (Test-Path .\package) {
3+
Remove-Item .\package -Recurse -Force
4+
}
5+
6+
New-Item .\package -type directory -f | Out-Null
7+
New-Item .\package\temp -type directory -f | Out-Null
8+
Write-Output "Copying dependencies..."
9+
Copy-Item .\backup.js .\package\temp\
10+
Copy-Item .\diff.js .\package\temp\
11+
Copy-Item .\s3-backfill.js .\package\temp\
12+
Copy-Item .\s3-snapshot.js .\package\temp\
13+
robocopy .\node_modules\ .\package\temp\ /E | Out-Null
14+
Write-Output "Dependencies sorted"
15+
16+
Write-Output "Generating output..."
17+
Copy-Item .\index.js .\package\temp\
18+
Write-Output "Output generated"
19+
20+
Add-Type -assembly "system.io.compression.filesystem"
21+
$currentPath = (Get-Item -Path ".\" -Verbose).FullName
22+
$sourcePath = $currentPath + "\package\temp"
23+
$outputFile = $currentPath + "\LambdaFunction.zip"
24+
25+
if (Test-Path $outputFile) {
26+
Remove-Item $outputFile -Force
27+
}
28+
29+
[io.compression.zipfile]::CreateFromDirectory($sourcePath, $outputFile)
30+
31+
Write-Output "λ function ready to be uploaded at: $($outputFile)"

s3-snapshot.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ module.exports = function(config, done) {
4747
var upload = s3.upload({
4848
Bucket: config.destination.bucket,
4949
Key: config.destination.key,
50-
Body: gzip
50+
Body: gzip,
51+
ACL: 'bucket-owner-full-control'
5152
}).on('httpUploadProgress', function(details) {
5253
if (details.part !== partsLoaded) {
5354
log(

0 commit comments

Comments
 (0)