Skip to content

Commit

Permalink
Merge branch 'release/0.1.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
kmcgrath committed Jul 6, 2016
2 parents f0a2876 + 456d972 commit 6978f3e
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 21 deletions.
22 changes: 17 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
language: node_js
node_js:
- stable
- v5
- v4
- '0.12'
after_script: NODE_ENV=test ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha --report lcovonly -- -R spec --timeout 15000 --recursive test/ && cat ./coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
- stable
- 5
- 4
- 4.3
- '0.12'
after_script: NODE_ENV=test ./node_modules/.bin/istanbul cover ./node_modules/.bin/_mocha
--report lcovonly -- -R spec --timeout 15000 --recursive test/ && cat ./coverage/lcov.info
| ./node_modules/coveralls/bin/coveralls.js && rm -rf ./coverage
deploy:
provider: npm
email: as.us.labs@sungardas.com
api_key:
secure: k/zolhE5OgAyrmhF4qCy9qQdDDJqK7ESjLWKTw3hSp1i4+jX2W+4mcMRK/FzwJiZCl8JgQRPbcYlzo/0fzvQsmYh11w/sDaRY5NvqxRR95MGMt02Ac4eGkx+ZGIM/eet8BYBLgT8DqOCpSdQo3bGOvaipbbwuVRxdaX80bHxDpch7I1eqWNQSX0OOwjKdfaotnmEHAPrmEXaA6aqJeSH0ND1+DhFAkcVBDK042Qs5BCvkOBlhWF1l9eKzCvVhr7iBqv6/ZtOJW3NygGICaToD0Mb+spLDUI1UGC0fqpZ+TaeS9LuKcLeft0jmqOnJLi3nUBL4LyDOu2XCJK1IX2pAGFY4OgAJbdWK+ru1ZwlS0Qbj0CQ2XdlMQYbMd1+36ODWzp8g7Ah6mkqvUExMfsMz9OnDzPDetPgZMEH8F2WoBu8gSPeZQ7lYGScAEE0IrR5GtkLu3qfw4VEr9eEu/NmONFqjZHcyrKBVzyNJCuh+hFHPl6V1PvmPbLApgtzIuOPXLgX9R2aJ80Ip1wVCQ/qo/Tt2oMPvS/lDI0ZiSJ6PSm2ROzMzWeV4pNy/0/628d9tDc2SoKipsNpnTpuNCTSUdlexDP6KZTu3IIoHGnpiEmr+DA8uY/gJ8cJEwPeXuqaDwLp6OP9hqhCCto37JvDZzAP9hgixFXMoQI9tisvAKg=
on:
tags: true
repo: SungardAS/cfn-responder
node: 4.3
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [0.1.6] - 2016-07-06

### Fixed
- When returning FAILED to CloudFormation exit the lambda function with
a success to prevent retries. [issue #1]

- Always return PhysicalResourceId, even for FAILED Create requests.
[issue #2]

## [0.1.5] - 2016-04-12

### Added
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ This module makes the following enhancements:

* Added check to ensure Data is a key/pair object. Prevents silent
failures after submitting to S3
* Will remove PhysicalResourceId when the `ResourceType` is `Create` and
the status is `FAILED` per the AWS [documentation](http://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/crpg-ref-requesttypes-create.html).
* Removes console.log statements in favor of forwarding request errors
to context.done directly
* Will ensure a PhysicalResourceId is always present even if the lambda
function does not have permissions to CloudWatch Logs
* For security console.log statements are removed to prevent leaking any
sensitive data. Request errors and return objects are sent context.done only

Any Lambda function using this module stops running after executing the module's send method.

Expand Down
15 changes: 7 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ exports.send = function(event, context, responseStatus, responseData, physicalRe
Data: responseData
};

if (!(event.RequestType === 'Create' && responseStatus === exports.FAILED)) {
jsonBody.PhysicalResourceId = physicalResourceId || context.logStreamName;
jsonBody.PhysicalResourceId = physicalResourceId || context.logStreamName;

// If this lambda function does not have permissions to CloudWatch Logs
// a PhysicalResourceId is still needed to send to CloudFormation.
if (event.RequestType === 'Create' && responseStatus === exports.FAILED && !jsonBody.PhysicalResourceId) {
jsonBody.PhysicalResourceId = exports.FAILED;
}

var responseBody = JSON.stringify(jsonBody);
Expand All @@ -39,14 +43,9 @@ exports.send = function(event, context, responseStatus, responseData, physicalRe
};

var request = https.request(options, function(response) {
if (response.statusCode === 200 && responseStatus === exports.SUCCESS)
if (response.statusCode === 200)
return context.done(null, jsonBody);

if (response.statusCode === 200 && responseStatus === exports.FAILED) {
console.error(jsonBody);
return context.done(jsonBody.Reason, jsonBody);
}

context.done("Failed to communicate to S3: " + response.statusCode,jsonBody);
});

Expand Down
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"name": "cfn-responder",
"version": "0.1.5",
"version": "0.1.6",
"publishConfig": {
"tag": "latest"
},
"description": "A module for sending CloudFormation compatible responses from AWS Lambda",
"main": "index.js",
"repository": {
Expand Down
6 changes: 3 additions & 3 deletions test/responder.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("cfn-responder", function() {
responder.send(event,context,responder.SUCCESS);
});

it("should remove PhysicalResourceId if the RequestType is Create and status is failed", function(cb) {
it("should contain a PhysicalResourceId if the RequestType is Create and status is failed", function(cb) {

nock('https://fake.url')
.put('/', {"Status":"FAILED","Reason":"See the details in CloudWatch Log Stream: undefined","StackId":"arn:aws:cloudformation:us-east-1:namespace:stack/stack-name/guid","RequestId":"unique id for this create request","LogicalResourceId":"name of resource in template","Data":{}})
Expand All @@ -52,9 +52,9 @@ describe("cfn-responder", function() {

var context = {
done: function(err,obj) {
assert(err);
assert.ifError(err);
assert(obj.RequestId);
assert.equal(obj.PhysicalResourceId,undefined);
assert.equal(obj.PhysicalResourceId,'FAILED');
cb();
}
};
Expand Down

0 comments on commit 6978f3e

Please sign in to comment.