Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Auto-remediation for check EKS-001 #67

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

gmagella-ca
Copy link

@gmagella-ca gmagella-ca commented Apr 8, 2020

Add auto-remediation for check EKS-001.
LambdaVersion had to be disabled in serverless.yaml to support the number of resources needed.

@PatrickQuintal PatrickQuintal requested review from PatrickQuintal and removed request for PatrickQuintal April 24, 2020 03:59
Copy link
Contributor

@binli0114 binli0114 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry about the delay PR review.
Left some comments and please let me know if any problem.

return handleError('Invalid event')
}

const clustername=event.resource.split('/')[1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const clustername=event.resource.split('/')[1];
const resourceItems = event.resource.split('/');
if (resourceItems.length<1){
return handleError('Invalid resource');
}
const clustername=resourceItems[1];

}
};

let eks = new AWS.EKS({region: event.region})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let eks = new AWS.EKS({region: event.region})
const eks = new AWS.EKS({region: event.region})

Comment on lines +26 to +27
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These if condition can be removed because line 29 handles it

Suggested change
if (err) console.log(err, err.stack); // an error occurred
else console.log(data); // successful response


let eks = new AWS.EKS({region: event.region})

eks.updateClusterConfig(params, function(err, data) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggest to use asynchronous flow instead of using callbacks.
ref: https://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/using-promises.html


module.exports.handler = (event, context, callback) => {
console.log('Received event: ', JSON.stringify(event, null, 2))
console.log('Config settings: ', JSON.stringify(CONFIG, null, 2))
//console.log('Config settings: ', JSON.stringify(CONFIG, null, 2))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove unused code

Suggested change
//console.log('Config settings: ', JSON.stringify(CONFIG, null, 2))

else{

//Compose the function name based on its own name...
let FunctionName =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let FunctionName =
const FunctionName =

Properties:
MessageRetentionPeriod: 7200 #2 Hours
QueueName: CloudConformityAutoRemediate

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SQS queue must be encrypted at rest. Please configure KMS KeyId in the queue property

'region': 'us-east-1'
}

let AutoRemediate = require('../functions/AutoRemediateEKS-001')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let AutoRemediate = require('../functions/AutoRemediateEKS-001')
const AutoRemediate = require('../functions/AutoRemediateEKS-001')

@@ -0,0 +1,11 @@
let event = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let event = {
const event = {


let AutoRemediate = require('../functions/AutoRemediateEKS-001')

AutoRemediate.handler(event, {}, function (err, data) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add valid unit tests here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants