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

Fix cannot find module 'aws-sdk' on custom config rule lambdas #1207

Merged
merged 1 commit into from
Jan 25, 2024
Merged
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
Binary file not shown.
Binary file modified reference-artifacts/config-rules/ec2-instance-profile.zip
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const AWS = require('aws-sdk');
AWS.config.logger = console;

const config = new AWS.ConfigService();
const { ConfigServiceClient, PutEvaluationsCommand } = require("@aws-sdk/client-config-service");
const client = new ConfigServiceClient();

const APPLICABLE_RESOURCES = ['AWS::IAM::Role'];

Expand All @@ -28,20 +26,20 @@ exports.handler = async function (event, context) {
console.debug(`Evaluation`);
console.debug(JSON.stringify(evaluation, null, 2));

await config
.putEvaluations({
ResultToken: event.resultToken,
Evaluations: [
{
ComplianceResourceId: configurationItem.resourceId,
ComplianceResourceType: configurationItem.resourceType,
ComplianceType: evaluation.complianceType,
OrderingTimestamp: configurationItem.configurationItemCaptureTime,
Annotation: evaluation.annotation,
},
],
})
.promise();
const payload = {
ResultToken: event.resultToken,
Evaluations: [
{
ComplianceResourceId: configurationItem.resourceId,
ComplianceResourceType: configurationItem.resourceType,
ComplianceType: evaluation.complianceType,
OrderingTimestamp: new Date(configurationItem.configurationItemCaptureTime),
Annotation: evaluation.annotation,
},
],
};
const putEvaluationsCommand = new PutEvaluationsCommand(payload);
await client.send(putEvaluationsCommand);
};

async function evaluateCompliance(props) {
Expand Down Expand Up @@ -84,7 +82,7 @@ async function evaluateCompliance(props) {
if (!existingPolicyNames.includes(requiredPolicy.trim())) {
return {
complianceType: 'NON_COMPLIANT',
annotation: 'The IAM Role is not having required polocies attached ' + requiredPolicy,
annotation: 'The IAM Role is not having required policies attached ' + requiredPolicy,
};
}
}
Expand All @@ -96,7 +94,7 @@ async function evaluateCompliance(props) {
if (!existingPolicyArns.includes(requiredPolicy.trim())) {
return {
complianceType: 'NON_COMPLIANT',
annotation: 'The IAM Role is not having required polocies attached ' + requiredPolicy,
annotation: 'The IAM Role is not having required policies attached ' + requiredPolicy,
};
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const AWS = require('aws-sdk');
AWS.config.logger = console;

const config = new AWS.ConfigService();
const { ConfigServiceClient, PutEvaluationsCommand } = require("@aws-sdk/client-config-service");
const client = new ConfigServiceClient();

const APPLICABLE_RESOURCES = ['AWS::EC2::Instance'];

Expand All @@ -23,18 +21,20 @@ exports.handler = async function(event, context) {
console.debug(`Evaluation`);
console.debug(JSON.stringify(evaluation, null, 2));

await config.putEvaluations({
const payload = {
ResultToken: event.resultToken,
Evaluations: [
{
ComplianceResourceId: configurationItem.resourceId,
ComplianceResourceType: configurationItem.resourceType,
ComplianceType: evaluation.complianceType,
OrderingTimestamp: configurationItem.configurationItemCaptureTime,
OrderingTimestamp: new Date(configurationItem.configurationItemCaptureTime),
Annotation: evaluation.annotation,
},
],
}).promise();
};
const putEvaluationsCommand = new PutEvaluationsCommand(payload);
await client.send(putEvaluationsCommand);
};

async function evaluateCompliance(props) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
const AWS = require('aws-sdk');
AWS.config.logger = console;

const config = new AWS.ConfigService();
const { ConfigServiceClient, PutEvaluationsCommand } = require("@aws-sdk/client-config-service");
const client = new ConfigServiceClient();

const APPLICABLE_RESOURCES = ['AWS::IAM::Role'];

Expand Down Expand Up @@ -29,20 +27,20 @@ exports.handler = async function (event, context) {
console.debug(`Evaluation`);
console.debug(JSON.stringify(evaluation, null, 2));

await config
.putEvaluations({
ResultToken: event.resultToken,
Evaluations: [
{
ComplianceResourceId: configurationItem.resourceId,
ComplianceResourceType: configurationItem.resourceType,
ComplianceType: evaluation.complianceType,
OrderingTimestamp: configurationItem.configurationItemCaptureTime,
Annotation: evaluation.annotation,
},
],
})
.promise();
const payload = {
ResultToken: event.resultToken,
Evaluations: [
{
ComplianceResourceId: configurationItem.resourceId,
ComplianceResourceType: configurationItem.resourceType,
ComplianceType: evaluation.complianceType,
OrderingTimestamp: new Date(configurationItem.configurationItemCaptureTime),
Annotation: evaluation.annotation,
},
],
};
const putEvaluationsCommand = new PutEvaluationsCommand(payload);
await client.send(putEvaluationsCommand);
};

async function evaluateCompliance(props) {
Expand Down
Binary file modified reference-artifacts/config-rules/ssm-patching-role-tags.zip
Binary file not shown.
Loading