Skip to content

Commit ce2541c

Browse files
committed
Merge pull request aws-samples#2 from willyg302/master
Fix indentation, use code block for command in readme
2 parents 8ba9c48 + 7c912e1 commit ce2541c

File tree

4 files changed

+58
-61
lines changed

4 files changed

+58
-61
lines changed

README.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
# AWS Lambda Reference Architecture: Real-time File Processing
22

3-
The [Real-time File Processing](https://s3.amazonaws.com/awslambda-reference-architectures/file-processing/lambda-refarch-fileprocessing.pdf) reference architecture is an general-purpose event-driven parallel data processing architecture that utilizes [AWS Lambda](https://aws.amazon.com/lambda). This architecture is ideal for workloads that need more than one data derivative of an object. This simple architecture is described in the [Fanout S3 Event Notifications to
4-
Multiple
5-
Endpoints](https://aws.amazon.com/blogs/compute/fanout-s3-event-notifications-to-multiple-endpoints/) blog post and can be created with two AWS CloudFormation templates.
3+
The [Real-time File Processing](https://s3.amazonaws.com/awslambda-reference-architectures/file-processing/lambda-refarch-fileprocessing.pdf) reference architecture is an general-purpose event-driven parallel data processing architecture that utilizes [AWS Lambda](https://aws.amazon.com/lambda). This architecture is ideal for workloads that need more than one data derivative of an object. This simple architecture is described in the [Fanout S3 Event Notifications to Multiple Endpoints](https://aws.amazon.com/blogs/compute/fanout-s3-event-notifications-to-multiple-endpoints/) blog post and can be created with two AWS CloudFormation templates.
64

7-
[Template
8-
One](https://s3.amazonaws.com/awslambda-reference-architectures/file-processing/lambda_file_processing.template)
5+
[Template One](https://s3.amazonaws.com/awslambda-reference-architectures/file-processing/lambda_file_processing.template)
96
does the following:
107

118
- Creates an Amazon Simple Storage Service (Amazon S3) bucket named event-manifold-bucket.
@@ -36,8 +33,7 @@ does the following:
3633
- Creates two custom resources, each of which invoke the Add
3734
Permission Lambda function for data-processor-1 and data-processor-2.
3835

39-
[Template
40-
Two](https://s3.amazonaws.com/awslambda-reference-architectures/file-processing/lambda_file_processing_update.template)
36+
[Template Two](https://s3.amazonaws.com/awslambda-reference-architectures/file-processing/lambda_file_processing_update.template)
4137
does the following:
4238

4339
- Configures the S3 bucket to send notifications to the
@@ -58,7 +54,9 @@ Step 3 – Navigate to the CloudWatch Logs tab.
5854
Step 4 – Upload a file to the event-manifold-bucket, for example by using the AWS
5955
Command Line Interface:
6056

61-
**aws s3 cp <some file> s3://event-manifold-bucket**
57+
```bash
58+
$ aws s3 cp <some_file> s3://event-manifold-bucket
59+
```
6260

6361
Step 5 – View the CloudWatch Log events for the data-processor-1 and
6462
data-processor-2 Lambda functions for evidence that both functions

add-permission.js

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,46 @@
11
/**
2-
* A Lambda function that sets the permissions for the specified SNS topic
3-
**/
2+
* A Lambda function that sets the permissions for the specified SNS topic
3+
*/
44
var aws = require("aws-sdk");
5-
5+
66
exports.handler = function(event, context) {
7-
7+
88
console.log("REQUEST RECEIVED:\n" + JSON.stringify(event));
9-
9+
1010
// For Delete requests, immediately send a SUCCESS response.
1111
if (event.RequestType == "Delete") {
1212
sendResponse(event, context, "SUCCESS");
1313
return;
1414
}
15-
15+
1616
var responseStatus = "FAILED";
1717
var responseData = {};
18-
18+
1919
var lambda = new aws.Lambda({region: event.ResourceProperties.Region});
2020
var addPermissionParams = {
21-
Action: 'lambda:InvokeFunction',
22-
FunctionName: event.ResourceProperties.LambdaFx,
23-
Principal: 'sns.amazonaws.com',
24-
StatementId: 'stmt-id-101',
21+
Action: 'lambda:InvokeFunction',
22+
FunctionName: event.ResourceProperties.LambdaFx,
23+
Principal: 'sns.amazonaws.com',
24+
StatementId: 'stmt-id-101',
2525
};
26-
26+
2727
// Get AMI IDs with the specified name pattern and owner
2828
lambda.addPermission(addPermissionParams, function(err, addPermissionResult) {
2929
if (err) {
3030
responseData = {Error: "Add Permission call failed"};
3131
console.log(responseData.Error + ":\n", err);
32-
}
33-
else {
34-
responseStatus = "SUCCESS";
35-
responseData = { "Result" : addPermissionResult };
32+
} else {
33+
responseStatus = "SUCCESS";
34+
responseData = { "Result" : addPermissionResult };
3635
}
3736
sendResponse(event, context, responseStatus, responseData);
3837
});
3938
};
4039

4140

42-
// Send response to the pre-signed S3 URL
41+
// Send response to the pre-signed S3 URL
4342
function sendResponse(event, context, responseStatus, responseData) {
44-
43+
4544
var responseBody = JSON.stringify({
4645
Status: responseStatus,
4746
Reason: "See the details in CloudWatch Log Stream: " + context.logStreamName,
@@ -51,12 +50,12 @@ function sendResponse(event, context, responseStatus, responseData) {
5150
LogicalResourceId: event.LogicalResourceId,
5251
Data: responseData
5352
});
54-
53+
5554
console.log("RESPONSE BODY:\n", responseBody);
56-
55+
5756
var https = require("https");
5857
var url = require("url");
59-
58+
6059
var parsedUrl = url.parse(event.ResponseURL);
6160
var options = {
6261
hostname: parsedUrl.hostname,
@@ -68,22 +67,22 @@ function sendResponse(event, context, responseStatus, responseData) {
6867
"content-length": responseBody.length
6968
}
7069
};
71-
70+
7271
console.log("SENDING RESPONSE...\n");
73-
72+
7473
var request = https.request(options, function(response) {
7574
console.log("STATUS: " + response.statusCode);
7675
console.log("HEADERS: " + JSON.stringify(response.headers));
77-
// Tell AWS Lambda that the function execution is done
76+
// Tell AWS Lambda that the function execution is done
7877
context.done();
7978
});
80-
79+
8180
request.on("error", function(error) {
8281
console.log("sendResponse Error:" + error);
83-
// Tell AWS Lambda that the function execution is done
82+
// Tell AWS Lambda that the function execution is done
8483
context.done();
8584
});
86-
85+
8786
// write data to request body
8887
request.write(responseBody);
8988
request.end();

data-processor-1.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
function getSNSMessageObject(msgString) {
2-
var x = msgString.replace(/\\/g,'');
3-
var y = x.substring(1,x.length-1);
4-
var z = JSON.parse(y);
5-
return z;
6-
}
2+
var x = msgString.replace(/\\/g, '');
3+
var y = x.substring(1, x.length - 1);
4+
var z = JSON.parse(y);
5+
return z;
6+
}
77

88
exports.handler = function(event, context) {
9-
console.log('event: '+JSON.stringify(event));
10-
var snsMsgString = JSON.stringify(event.Records[0].Sns.Message);
11-
var snsMsgObject = getSNSMessageObject(snsMsgString);
12-
var srcBucket = snsMsgObject.Records[0].s3.bucket.name;
13-
var srcKey = snsMsgObject.Records[0].s3.object.key;
14-
console.log('SRC Bucket from data processor 1: ' + srcBucket);
15-
console.log('SRC Keyfrom data processor 1: ' + srcKey);
9+
console.log('event: '+JSON.stringify(event));
10+
var snsMsgString = JSON.stringify(event.Records[0].Sns.Message);
11+
var snsMsgObject = getSNSMessageObject(snsMsgString);
12+
var srcBucket = snsMsgObject.Records[0].s3.bucket.name;
13+
var srcKey = snsMsgObject.Records[0].s3.object.key;
14+
console.log('SRC Bucket from data processor 1: ' + srcBucket);
15+
console.log('SRC Keyfrom data processor 1: ' + srcKey);
1616

17-
context.succeed(null);
17+
context.succeed(null);
1818
};

data-processor-2.js

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
function getSNSMessageObject(msgString) {
2-
var x = msgString.replace(/\\/g,'');
3-
var y = x.substring(1,x.length-1);
4-
var z = JSON.parse(y);
5-
return z;
6-
}
2+
var x = msgString.replace(/\\/g, '');
3+
var y = x.substring(1, x.length - 1);
4+
var z = JSON.parse(y);
5+
return z;
6+
}
77

88
exports.handler = function(event, context) {
9-
console.log('event: '+JSON.stringify(event));
10-
var snsMsgString = JSON.stringify(event.Records[0].Sns.Message);
11-
var snsMsgObject = getSNSMessageObject(snsMsgString);
12-
var srcBucket = snsMsgObject.Records[0].s3.bucket.name;
13-
var srcKey = snsMsgObject.Records[0].s3.object.key;
14-
console.log('SRC Bucket from data processor 2: ' + srcBucket);
15-
console.log('SRC Keyfrom data processor 2: ' + srcKey);
9+
console.log('event: '+JSON.stringify(event));
10+
var snsMsgString = JSON.stringify(event.Records[0].Sns.Message);
11+
var snsMsgObject = getSNSMessageObject(snsMsgString);
12+
var srcBucket = snsMsgObject.Records[0].s3.bucket.name;
13+
var srcKey = snsMsgObject.Records[0].s3.object.key;
14+
console.log('SRC Bucket from data processor 2: ' + srcBucket);
15+
console.log('SRC Keyfrom data processor 2: ' + srcKey);
1616

17-
context.succeed(null);
17+
context.succeed(null);
1818
};

0 commit comments

Comments
 (0)