Skip to content
This repository was archived by the owner on Jan 22, 2026. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion preTrafficHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ exports.handler = (event, context, callback) => {
// "statusCode": 200,
// "body": 51
// }
if(result.body == 9){
if(result.body == 29){
lambdaResult = "Succeeded";
console.log ("Validation testing succeeded!");
}
Expand Down
59 changes: 31 additions & 28 deletions returnS3Buckets.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
1/*
* Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this
Expand All @@ -15,30 +15,33 @@
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

'use strict';

var AWS = require('aws-sdk');
var s3 = new AWS.S3();

exports.handler = (event, context, callback) => {
console.log("I am here! " + context.functionName + ":" + context.functionVersion);

s3.listBuckets(function (err, data){
if(err){
console.log(err, err.stack);
callback(null, {
statusCode: 500,
body: "Failed!"
});
}
else{
var allBuckets = data.Buckets;

console.log("Total buckets: " + allBuckets.length);
callback(null, {
statusCode: 200,
body: allBuckets.length
});
}
});
}
'use strict';

const AWS = require('aws-sdk');
const s3 = new AWS.S3();

exports.handler = async (event, context) => {
console.log(`I am here! " ${context.functionName} + ":" + ${context.functionVersion}`);
let response
try {
const data = await s3.listBuckets().promise();
const allBuckets = data.Buckets;

console.log(`Total buckets: ${allBuckets.length}`)

response = {
statusCode: 200,
body: allBuckets.length
};

} catch (error) {
console.log(`Error - `, error, error.stack);
return {
statusCode: 500,
body: JSON.stringify(error)
};
}

return response
}

71 changes: 36 additions & 35 deletions returnS3BucketsNew.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,39 +17,40 @@

'use strict';

var AWS = require('aws-sdk');
var s3 = new AWS.S3();

exports.handler = (event, context, callback) => {
console.log("I am here! " + context.functionName + ":" + context.functionVersion);

s3.listBuckets(function (err, data){
if(err){
console.log(err, err.stack);
callback(null, {
statusCode: 500,
body: "Failed!"
});
}
else{
var allBuckets = data.Buckets;

console.log("Total buckets: " + allBuckets.length);
//callback(null, allBuckets.length);

// New Code begins here
var counter=0;
for(var i in allBuckets){
if(allBuckets[i].Name[0] === "a")
counter++;
}
console.log("Total buckets starting with a: " + counter);

callback(null, {
statusCode: 200,
body: counter
});

const AWS = require('aws-sdk');
const s3 = new AWS.S3();

exports.handler = async (event, context) => {
console.log(`I am here! " ${context.functionName} + ":" + ${context.functionVersion}`);

let response
try {

const data = await s3.listBuckets().promise();
const allBuckets = data.Buckets;

console.log(`Total buckets: ${allBuckets.length}`)

// New Code begins here
let counter = 0;
for (var i in allBuckets) {
if (allBuckets[i].Name[0] === "a")
counter++;
}
});
}
console.log(`Total buckets starting with a: ${counter}`);

response = {
statusCode: 200,
body: counter
};

} catch (error) {
console.log(`Error - `, error, error.stack);
return {
statusCode: 500,
body: JSON.stringify(error)
};
}

return response
}
4 changes: 2 additions & 2 deletions template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Resources:
Type: AWS::Serverless::Function
Properties:
Handler: returnS3Buckets.handler
Runtime: nodejs6.10
Runtime: nodejs10.x
AutoPublishAlias: live
Policies:
- Version: "2012-10-17"
Expand Down Expand Up @@ -46,7 +46,7 @@ Resources:
Action:
- "lambda:InvokeFunction"
Resource: !Ref returnS3Buckets.Version
Runtime: nodejs6.10
Runtime: nodejs10.x
FunctionName: 'CodeDeployHook_preTrafficHook'
DeploymentPreference:
Enabled: false
Expand Down