Skip to content

Commit a5533e2

Browse files
Merge pull request #1 from awslabs/master
Merge from Master
2 parents 51169b3 + 6928e36 commit a5533e2

33 files changed

+907
-249
lines changed

Networking.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
In this model, your Redshift cluster is in a VPC Subnet, and we recommend using [AWS Lambda VPC Endpoints](http://docs.aws.amazon.com/lambda/latest/dg/vpc.html) to manage access to your cluster. The following diagram represents the configuration required to successfully run this solution in a VPC:
66

7-
![VPC Connectivity](VPCConnectivity.png)
7+
![VPC Connectivity](img/VPCConnectivity.png)
88

99
In this architecture, you expose your AWS Lambda function into a set of private VPC subnets, and then select a security group for your Lambda function. Ideally this would be the same security group as the Redshift cluster was using, but you can also use security group grants to enable access between two SG's. Your Lambda function must also have internet egress enabled so it can read its configuration from DynamoDB, and the easiest way to do this is to use [VPC NAT Gateway](http://docs.aws.amazon.com/AmazonVPC/latest/UserGuide/vpc-nat-gateway.html). The following steps should be undertaken:
1010

1111
_VPC_
1212

1313
To use Lambda in a VPC, we recommend having both a private and public subnet per AZ. Your Lambda function is enabled to run within the Private AZ, and a NAT Gateway is created in the Public AZ. Your Private Subnets will each have their own Route Table, with a route for 0.0.0.0/0 (public internet) routed to the NAT Gateway in the same AZ. Your Public Subnets will all share a Route Table which routes 0.0.0.0/0 to the Internet Gateway.
1414

15-
![VPCPerAZ](VPCPerAZ.png)
15+
![VPCPerAZ](img/VPCPerAZ.png)
1616

1717
_AWS Lambda_
1818

@@ -47,5 +47,5 @@ INSERT using GRANT (http://docs.aws.amazon.com/redshift/latest/dg/r_GRANT.html).
4747

4848
To configure environment variable of your Lambda function:
4949

50-
1. Add a variable. Key is "https_proxy".
51-
2. Fill a variable. For example, http://proxy.example.org:3128
50+
1. Add a variable. Key is `https_proxy`.
51+
2. Fill a variable. For example `http://proxy.example.org:3128`

README.md

Lines changed: 234 additions & 127 deletions
Large diffs are not rendered by default.

build.sh renamed to bin/build.sh

File renamed without changes.

bin/deploy-yaml.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
# publish deploy.yaml to regional buckets
4+
for r in `aws ec2 describe-regions --query Regions[*].RegionName --output text`; do aws s3 cp deploy.yaml s3://awslabs-code-$r/LambdaRedshiftLoader/deploy.yaml --acl public-read --region $r; done

bin/deploy.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
#set -x
3+
4+
ver=`cat package.json | grep "version" | cut -d: -f2 | sed -e "s/[\"\,]//g" | tr -d '[:space:]'`
5+
token=AWSLambdaRedshiftLoader
6+
7+
for r in `aws ec2 describe-regions --query Regions[*].RegionName --output text`; do
8+
aws s3 cp dist/$token-$ver.zip s3://awslabs-code-$r/LambdaRedshiftLoader/$token-$ver.zip --acl public-read --region $r;
9+
done

bin/generate-readme-table.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/bash
2+
3+
for r in `aws ec2 describe-regions --query Regions[*].RegionName --output text`; do echo "|$r | [<img src=\"https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png\" target=\”_blank\”>](https://console.aws.amazon.com/cloudformation/home?region=$r#/stacks/new?stackName=LambdaRedshiftLoader&templateURL=https://s3-$r.amazonaws.com/awslabs-code-$r/LambdaRedshiftLoader/deploy.yaml) |"; done
4+

bin/generate-s3table.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
#set -x
3+
4+
ver=`cat package.json | grep "version" | cut -d: -f2 | sed -e "s/[\"\,]//g" | tr -d '[:space:]'`
5+
token=AWSLambdaRedshiftLoader
6+
project_prefix=LambdaRedshiftLoader
7+
8+
for r in `aws ec2 describe-regions --query Regions[*].RegionName --output text`; do
9+
if [ "$r" == "us-east-1" ]; then
10+
region="."
11+
else
12+
region=".$r."
13+
fi
14+
prefix="amazonaws.com/awslabs-code-$r/$project_prefix/$token-$ver.zip"
15+
link="https://s3$region$prefix"
16+
echo "| $r | [s3://awslabs-code-$r/$project_prefix/$token-$ver.zip]($link)"
17+
done

bin/remove-version.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
#set -x
3+
4+
ver=$1
5+
token=AWSLambdaRedshiftLoader
6+
7+
for r in `aws ec2 describe-regions --query Regions[*].RegionName --output text`; do
8+
aws s3 rm s3://awslabs-code-$r/LambdaRedshiftLoader/$token-$ver.zip --region $r;
9+
done

common.js

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,7 @@ exports.createTables = function (dynamoDB, callback) {
8181
KeyType: 'HASH'
8282
}],
8383
TableName: filesTable,
84-
ProvisionedThroughput: {
85-
ReadCapacityUnits: 5,
86-
WriteCapacityUnits: 5
87-
}
84+
BillingMode: "PAY_PER_REQUEST"
8885
};
8986
var configKey = s3prefix;
9087
var configSpec = {
@@ -97,10 +94,7 @@ exports.createTables = function (dynamoDB, callback) {
9794
KeyType: 'HASH'
9895
}],
9996
TableName: configTable,
100-
ProvisionedThroughput: {
101-
ReadCapacityUnits: 5,
102-
WriteCapacityUnits: 5
103-
}
97+
BillingMode: "PAY_PER_REQUEST"
10498
};
10599

106100
var batchKey = batchId;
@@ -127,10 +121,7 @@ exports.createTables = function (dynamoDB, callback) {
127121
KeyType: 'RANGE'
128122
}],
129123
TableName: batchTable,
130-
ProvisionedThroughput: {
131-
ReadCapacityUnits: 1,
132-
WriteCapacityUnits: 5
133-
},
124+
BillingMode: "PAY_PER_REQUEST",
134125
GlobalSecondaryIndexes: [{
135126
IndexName: batchStatusGSI,
136127
KeySchema: [{
@@ -389,7 +380,7 @@ exports.getS3NotificationConfiguration = function (s3, bucket, prefix, functionA
389380
if (data.LambdaFunctionConfigurations && data.LambdaFunctionConfigurations.length > 0) {
390381
var matchConfigId;
391382
data.LambdaFunctionConfigurations.map(function (item) {
392-
if (item.Filter.Key.FilterRules) {
383+
if (item && item.Filter && item.Filter.Key && item.Filter.Key.FilterRules) {
393384
item.Filter.Key.FilterRules.map(function (filter) {
394385
if (filter.Name === 'Prefix' && filter.Value === prefix) {
395386
if (item.LambdaFunctionArn === functionArn) {
@@ -704,6 +695,21 @@ exports.deleteFile = function (dynamoDB, region, file, callback) {
704695
});
705696
}
706697

698+
exports.queryFile = function (dynamoDB, region, file, callback) {
699+
var fileItem = {
700+
Key: {
701+
loadFile: {
702+
S: file
703+
}
704+
},
705+
TableName: filesTable
706+
};
707+
708+
dynamoDB.getItem(fileItem, function (err, data) {
709+
callback(err, data);
710+
});
711+
}
712+
707713
exports.reprocessFile = function (dynamoDB, s3, region, file, callback) {
708714
// get the file so we know what the current batch ID is
709715
var fileItem = {

config.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
"table": "sensor_data_raw",
1010
"columnList": "",
1111
"truncateTable": "N",
12+
"presql": "",
13+
"postsql": "",
1214
"userName": "master",
1315
"userPwd": " ",
1416
"df": "CSV",
@@ -27,4 +29,4 @@
2729
"batchTimeoutSecs": "120",
2830
"copyOptions": "",
2931
"symmetricKey": ""
30-
}
32+
}

0 commit comments

Comments
 (0)