Skip to content

Commit 40f93df

Browse files
committed
Version 2.7.3
Migrated to Winston logging Added more debug logging Added environment configurable log level Doc updates for sample config.json Doc update for current version
1 parent 7ba089f commit 40f93df

12 files changed

+892
-600
lines changed

README.md

Lines changed: 28 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ The template requires four input parameters: availability zone, a security group
100100

101101
__Usage Steps__
102102

103-
1. Create a CloudFormation stack with the deploy.yaml file, or use the table of links below. This stack will include everything needed to set up the autoloader with two exceptions. The KMS key must be created and managed separately, and a RedShift cluster will be required when setting up the autoloader. Note that this stack does not configure the autoloader - it just installs the components required to run the node setup script.
103+
1. Create a CloudFormation stack with the deploy.yaml file, or launch using the table of links below. This stack will include everything needed to set up the autoloader with two exceptions. The KMS key must be created and managed separately, and a RedShift cluster will be required when setting up the autoloader. Note that this stack does not configure the autoloader - it just installs the components required to run the node setup script.
104104
2. Log in to the EC2 instance created as part of the stack. It contains all the necessary components set up the autoloader.
105105
3. Invoke the `setup.js` script on the created EC2 instance to begin configuring the autoloader.
106106

@@ -133,70 +133,23 @@ __Launch Links__
133133
|us-west-1 | [<img src="https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png" target=\”_blank\”>](https://console.aws.amazon.com/cloudformation/home?region=us-west-1#/stacks/new?stackName=LambdaRedshiftLoader&templateURL=https://awslabs-code-us-west-1.s3.amazonaws.com/LambdaRedshiftLoader/deploy.yaml) |
134134
|us-west-2 | [<img src="https://s3.amazonaws.com/cloudformation-examples/cloudformation-launch-stack.png" target=\”_blank\”>](https://console.aws.amazon.com/cloudformation/home?region=us-west-2#/stacks/new?stackName=LambdaRedshiftLoader&templateURL=https://awslabs-code-us-west-2.s3.amazonaws.com/LambdaRedshiftLoader/deploy.yaml) |
135135

136+
### Function Configuration
137+
138+
You can set the logging behaviour of the function by adding environment variables:
139+
140+
* `DEBUG` Sets log level debug and all messages will be shown in CloudWatch Logs
141+
* `LOG_LEVEL` Sets the log level to whatever you require, per [Winston documentation](https://github.com/winstonjs/winston#logging-levels)
142+
136143
## Installing Manually
137144

145+
This option is not recommended, but can be used if you just want to patch the binaries, etc. Proceed with caution.
146+
138147
### Before you deploy - Lambda Execution Role
139148

140149
You need to create an IAM policy that AWS Lambda
141150
uses when it runs, and allows it to call SNS, use DynamoDB, write Manifest
142151
files to S3, perform encryption with the AWS Key Management Service, and pass STS temporary
143-
credentials to Redshift for the COPY command:
144-
145-
```
146-
{
147-
"Version": "2012-10-17",
148-
"Statement": [
149-
{
150-
"Sid": "Stmt1424787824000",
151-
"Effect": "Allow",
152-
"Action": [
153-
"dynamodb:DeleteItem",
154-
"dynamodb:DescribeTable",
155-
"dynamodb:GetItem",
156-
"dynamodb:ListTables",
157-
"dynamodb:PutItem",
158-
"dynamodb:Query",
159-
"dynamodb:Scan",
160-
"dynamodb:UpdateItem"
161-
],
162-
"Resource": [
163-
"arn:aws:dynamodb:<my region>:<my account>:table/LambdaRedshiftBatches",
164-
"arn:aws:dynamodb:<my region>:<my account>:table/LambdaRedshiftBatchLoadConfig",
165-
"arn:aws:dynamodb:<my region>:<my account>:table/LambdaRedshiftProcessedFiles"
166-
]
167-
},
168-
{
169-
"Sid": "Stmt1424787824001",
170-
"Effect": "Allow",
171-
"Action": [
172-
"sns:GetEndpointAttributes",
173-
"sns:GetSubscriptionAttributes",
174-
"sns:GetTopicAttributes",
175-
"sns:ListTopics",
176-
"sns:Publish",
177-
"sns:Subscribe",
178-
"sns:Unsubscribe"
179-
],
180-
"Resource": [
181-
"arn:aws:sns:<my region>:<my account>:<success topic>",
182-
"arn:aws:sns:<my region>:<my account>:<failure topic>"
183-
]
184-
},
185-
{
186-
"Sid": "Stmt1424787824002",
187-
"Effect": "Allow",
188-
"Action": [
189-
"kms:Decrypt",
190-
"kms:DescribeKey",
191-
"kms:GetKeyPolicy"
192-
],
193-
"Resource": [
194-
"arn:aws:kms:<my region>:<my account>:key/<key name>"
195-
]
196-
}
197-
]
198-
}
199-
```
152+
credentials to Redshift for the COPY command. We recommend that you obtain the required permissions from the contents of the deploy.yaml as they will always be up to date.
200153

201154
### Deploy the function
202155

@@ -210,23 +163,23 @@ credentials to Redshift for the COPY command:
210163

211164
| Region | Function Code S3 Location |
212165
| ------ | ---- |
213-
| eu-north-1 | [s3://awslabs-code-eu-north-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip](https://s3.eu-north-1.amazonaws.com/awslabs-code-eu-north-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip)
214-
| ap-south-1 | [s3://awslabs-code-ap-south-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip](https://s3.ap-south-1.amazonaws.com/awslabs-code-ap-south-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip)
215-
| eu-west-3 | [s3://awslabs-code-eu-west-3/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip](https://s3.eu-west-3.amazonaws.com/awslabs-code-eu-west-3/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip)
216-
| eu-west-2 | [s3://awslabs-code-eu-west-2/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip](https://s3.eu-west-2.amazonaws.com/awslabs-code-eu-west-2/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip)
217-
| eu-west-1 | [s3://awslabs-code-eu-west-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip](https://s3.eu-west-1.amazonaws.com/awslabs-code-eu-west-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip)
218-
| ap-northeast-3 | [s3://awslabs-code-ap-northeast-3/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip](https://s3.ap-northeast-3.amazonaws.com/awslabs-code-ap-northeast-3/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip)
219-
| ap-northeast-2 | [s3://awslabs-code-ap-northeast-2/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip](https://s3.ap-northeast-2.amazonaws.com/awslabs-code-ap-northeast-2/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip)
220-
| ap-northeast-1 | [s3://awslabs-code-ap-northeast-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip](https://s3.ap-northeast-1.amazonaws.com/awslabs-code-ap-northeast-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip)
221-
| sa-east-1 | [s3://awslabs-code-sa-east-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip](https://s3.sa-east-1.amazonaws.com/awslabs-code-sa-east-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip)
222-
| ca-central-1 | [s3://awslabs-code-ca-central-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip](https://s3.ca-central-1.amazonaws.com/awslabs-code-ca-central-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip)
223-
| ap-southeast-1 | [s3://awslabs-code-ap-southeast-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip](https://s3.ap-southeast-1.amazonaws.com/awslabs-code-ap-southeast-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip)
224-
| ap-southeast-2 | [s3://awslabs-code-ap-southeast-2/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip](https://s3.ap-southeast-2.amazonaws.com/awslabs-code-ap-southeast-2/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip)
225-
| eu-central-1 | [s3://awslabs-code-eu-central-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip](https://s3.eu-central-1.amazonaws.com/awslabs-code-eu-central-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip)
226-
| us-east-1 | [s3://awslabs-code-us-east-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip](https://s3.amazonaws.com/awslabs-code-us-east-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip)
227-
| us-east-2 | [s3://awslabs-code-us-east-2/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip](https://s3.us-east-2.amazonaws.com/awslabs-code-us-east-2/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip)
228-
| us-west-1 | [s3://awslabs-code-us-west-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip](https://s3.us-west-1.amazonaws.com/awslabs-code-us-west-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip)
229-
| us-west-2 | [s3://awslabs-code-us-west-2/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip](https://s3.us-west-2.amazonaws.com/awslabs-code-us-west-2/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.0.zip)
166+
| eu-north-1 | [s3://awslabs-code-eu-north-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip](https://s3.eu-north-1.amazonaws.com/awslabs-code-eu-north-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip)
167+
| ap-south-1 | [s3://awslabs-code-ap-south-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip](https://s3.ap-south-1.amazonaws.com/awslabs-code-ap-south-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip)
168+
| eu-west-3 | [s3://awslabs-code-eu-west-3/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip](https://s3.eu-west-3.amazonaws.com/awslabs-code-eu-west-3/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip)
169+
| eu-west-2 | [s3://awslabs-code-eu-west-2/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip](https://s3.eu-west-2.amazonaws.com/awslabs-code-eu-west-2/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip)
170+
| eu-west-1 | [s3://awslabs-code-eu-west-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip](https://s3.eu-west-1.amazonaws.com/awslabs-code-eu-west-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip)
171+
| ap-northeast-3 | [s3://awslabs-code-ap-northeast-3/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip](https://s3.ap-northeast-3.amazonaws.com/awslabs-code-ap-northeast-3/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip)
172+
| ap-northeast-2 | [s3://awslabs-code-ap-northeast-2/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip](https://s3.ap-northeast-2.amazonaws.com/awslabs-code-ap-northeast-2/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip)
173+
| ap-northeast-1 | [s3://awslabs-code-ap-northeast-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip](https://s3.ap-northeast-1.amazonaws.com/awslabs-code-ap-northeast-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip)
174+
| sa-east-1 | [s3://awslabs-code-sa-east-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip](https://s3.sa-east-1.amazonaws.com/awslabs-code-sa-east-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip)
175+
| ca-central-1 | [s3://awslabs-code-ca-central-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip](https://s3.ca-central-1.amazonaws.com/awslabs-code-ca-central-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip)
176+
| ap-southeast-1 | [s3://awslabs-code-ap-southeast-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip](https://s3.ap-southeast-1.amazonaws.com/awslabs-code-ap-southeast-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip)
177+
| ap-southeast-2 | [s3://awslabs-code-ap-southeast-2/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip](https://s3.ap-southeast-2.amazonaws.com/awslabs-code-ap-southeast-2/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip)
178+
| eu-central-1 | [s3://awslabs-code-eu-central-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip](https://s3.eu-central-1.amazonaws.com/awslabs-code-eu-central-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip)
179+
| us-east-1 | [s3://awslabs-code-us-east-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip](https://s3.amazonaws.com/awslabs-code-us-east-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip)
180+
| us-east-2 | [s3://awslabs-code-us-east-2/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip](https://s3.us-east-2.amazonaws.com/awslabs-code-us-east-2/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip)
181+
| us-west-1 | [s3://awslabs-code-us-west-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip](https://s3.us-west-1.amazonaws.com/awslabs-code-us-west-1/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip)
182+
| us-west-2 | [s3://awslabs-code-us-west-2/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip](https://s3.us-west-2.amazonaws.com/awslabs-code-us-west-2/LambdaRedshiftLoader/AWSLambdaRedshiftLoader-2.7.3.zip)
230183

231184
When you're done, you'll see that the AWS Lambda function is deployed and you
232185
can submit test events and view the CloudWatch Logging log streams.

batchOperations.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,18 @@ var async = require('async');
55
var debug = true;
66
var dynamoDB;
77
var s3;
8+
var debug = (process.env['DEBUG'] === 'true');
9+
var log_level = process.env['LOG_LEVEL'] || 'info';
10+
const winston = require('winston');
11+
12+
const logger = winston.createLogger({
13+
level: debug === true ? 'debug' : log_level,
14+
transports: [
15+
new winston.transports.Console({
16+
format: winston.format.simple()
17+
})
18+
]
19+
});
820

921
/**
1022
* Initialisation for the module - connect to DDB etc
@@ -145,7 +157,7 @@ function doQuery(setRegion, batchStatus, queryStartDate, queryEndDate, callback)
145157

146158
dynamoDB.query(queryParams, function (err, data) {
147159
if (err) {
148-
console.log(err);
160+
logger.error(err);
149161
process.exit(ERROR);
150162
} else {
151163
if (data && data.Items) {
@@ -220,7 +232,7 @@ function deleteBatches(setRegion, batchStatus, startDate, endDate, dryRun, callb
220232
callback(err);
221233
} else {
222234
if (dryRun && !JSON.parse(dryRun)) {
223-
console.log("Deleting " + data.length + " Batches in status " + batchStatus);
235+
logger.info("Deleting " + data.length + " Batches in status " + batchStatus);
224236

225237
async.map(data, function (batchItem, asyncCallback) {
226238
// pass the request through the function that deletes the
@@ -244,8 +256,8 @@ function deleteBatches(setRegion, batchStatus, startDate, endDate, dryRun, callb
244256
}
245257
});
246258
} else {
247-
console.log("Dry run only - no batches will be modified");
248-
console.log("Resolved " + data.length + " Batches for Deletion");
259+
logger.info("Dry run only - no batches will be modified");
260+
logger.info("Resolved " + data.length + " Batches for Deletion");
249261
callback(null, {
250262
batchCountDeleted: 0,
251263
batchesDeleted: data
@@ -272,11 +284,11 @@ function reprocessBatch(s3Prefix, batchId, region, omitFiles, callback) {
272284
if (data) {
273285
if (!data.entries.SS) {
274286
msg = "Batch is Empty!";
275-
console.log(msg);
287+
logger.info(msg);
276288
callback(msg);
277289
} else if (data.status.S === open) {
278290
msg = "Cannot reprocess an Open Batch";
279-
console.log(msg);
291+
logger.error(msg);
280292
callback(msg);
281293
} else {
282294
// the batch to be unlocked must be in locked or error state - we
@@ -331,7 +343,7 @@ function reprocessBatch(s3Prefix, batchId, region, omitFiles, callback) {
331343
}
332344
} else {
333345
msg = "Unable to retrieve batch " + batchId + " for prefix " + s3Prefix;
334-
console.log(msg);
346+
logger.error(msg);
335347
callback(msg);
336348
}
337349
}

0 commit comments

Comments
 (0)