Skip to content
This repository has been archived by the owner on Sep 18, 2023. It is now read-only.

Commit

Permalink
Upgrading to Node.js 18
Browse files Browse the repository at this point in the history
  • Loading branch information
andreaswittig committed Sep 1, 2023
1 parent 2d3c2e6 commit 4a5316f
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 64 deletions.
49 changes: 25 additions & 24 deletions marbot-cloudformation-drift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ Resources:
Type: 'AWS::Lambda::Function'
Properties:
Handler: 'index.handler'
Runtime: 'nodejs16.x'
Runtime: 'nodejs18.x'
MemorySize: 128
Timeout: 30
Role: !GetAtt 'RoleTrigger.Arn'
Expand All @@ -436,20 +436,21 @@ Resources:
Code:
ZipFile: |
'use strict';
const AWS = require('aws-sdk')
const cloudformation = new AWS.CloudFormation({apiVersion: '2010-05-15'});
const stepfunctions = new AWS.StepFunctions({apiVersion: '2016-11-23'});
const { CloudFormationClient, ListStacksCommand } = require('@aws-sdk/client-cloudformation');
const cloudformation = new CloudFormationClient({apiVersion: '2010-05-15'});
const { SFNClient, StartExecutionCommand } = require('@aws-sdk/client-sfn');
const stepfunctions = new SFNClient({apiVersion: '2016-11-23'});
let trigger = async (nextToken) => {
let params = {
StackStatusFilter: ['CREATE_COMPLETE', 'UPDATE_COMPLETE', 'UPDATE_ROLLBACK_COMPLETE', 'UPDATE_ROLLBACK_FAILED']
}
if (nextToken) {
params.NextToken = nextToken;
}
const listStacksResult = await cloudformation.listStacks(params).promise();
const listStacksResult = await cloudformation.send(new ListStacksCommand(params));
const stacks = listStacksResult.StackSummaries.filter(stack => stack.StackName.match(new RegExp(process.env.STACK_REGEXP)));
for (let stack of stacks) {
await stepfunctions.startExecution({stateMachineArn: process.env.STATEMACHINE_ARN, input: JSON.stringify({stackName: stack.StackName})}).promise();
await stepfunctions.send(new StartExecutionCommand({stateMachineArn: process.env.STATEMACHINE_ARN, input: JSON.stringify({stackName: stack.StackName})}));
}
if (listStacksResult.NextToken) {
trigger(listStacksResult.NextToken);
Expand All @@ -468,17 +469,17 @@ Resources:
Type: 'AWS::Lambda::Function'
Properties:
Handler: 'index.handler'
Runtime: 'nodejs16.x'
Runtime: 'nodejs18.x'
MemorySize: 128
Timeout: 30
Role: !GetAtt 'RoleFetchDriftStatus.Arn'
Code:
ZipFile: |
'use strict';
const AWS = require('aws-sdk')
const cloudformation = new AWS.CloudFormation({apiVersion: '2010-05-15'});
const { CloudFormationClient, DescribeStacksCommand } = require('@aws-sdk/client-cloudformation');
const cloudformation = new CloudFormationClient({apiVersion: '2010-05-15'});
exports.handler = async (event, context) => {
const result = await cloudformation.describeStacks({StackName: event.stackName}).promise();
const result = await cloudformation.send(new DescribeStacksCommand({StackName: event.stackName}));
const driftStatus = result.Stacks[0].DriftInformation.StackDriftStatus;
const arn = result.Stacks[0].StackId;
return Object.assign({}, event, {previousDriftStatus: driftStatus, stackArn: arn});
Expand All @@ -492,17 +493,17 @@ Resources:
Type: 'AWS::Lambda::Function'
Properties:
Handler: 'index.handler'
Runtime: 'nodejs16.x'
Runtime: 'nodejs18.x'
MemorySize: 128
Timeout: 30
Role: !GetAtt 'RoleStartDriftDetection.Arn'
Code:
ZipFile: |
'use strict';
const AWS = require('aws-sdk')
const cloudformation = new AWS.CloudFormation({apiVersion: '2010-05-15'});
const { CloudFormationClient, DetectStackDriftCommand } = require('@aws-sdk/client-cloudformation');
const cloudformation = new CloudFormationClient({apiVersion: '2010-05-15'});
exports.handler = async (event, context) => {
const result = await cloudformation.detectStackDrift({StackName: event.stackName}).promise();
const result = await cloudformation.send(new DetectStackDriftCommand({StackName: event.stackName}));
return Object.assign({}, event, {stackDriftDetectionId: result.StackDriftDetectionId});
};
LogGroupStartDriftDetection:
Expand All @@ -514,17 +515,17 @@ Resources:
Type: 'AWS::Lambda::Function'
Properties:
Handler: 'index.handler'
Runtime: 'nodejs16.x'
Runtime: 'nodejs18.x'
MemorySize: 128
Timeout: 30
Role: !GetAtt 'RoleFetchDetectionStatus.Arn'
Code:
ZipFile: |
'use strict';
const AWS = require('aws-sdk')
const cloudformation = new AWS.CloudFormation({apiVersion: '2010-05-15'});
const { CloudFormationClient, DescribeStackDriftDetectionStatusCommand } = require('@aws-sdk/client-cloudformation');

Check failure on line 525 in marbot-cloudformation-drift.yml

View workflow job for this annotation

GitHub Actions / test

525:128 [trailing-spaces] trailing spaces
const cloudformation = new CloudFormationClient({apiVersion: '2010-05-15'});
exports.handler = async (event, context) => {
const result = await cloudformation.describeStackDriftDetectionStatus({StackDriftDetectionId: event.stackDriftDetectionId}).promise();
const result = await cloudformation.send(new DescribeStackDriftDetectionStatusCommand({StackDriftDetectionId: event.stackDriftDetectionId}));
return Object.assign({}, event, {detectionStatus: result.DetectionStatus, latestDriftStatus: result.StackDriftStatus});
};
LogGroupFetchDetectionStatus:
Expand All @@ -536,7 +537,7 @@ Resources:
Type: 'AWS::Lambda::Function'
Properties:
Handler: 'index.handler'
Runtime: 'nodejs16.x'
Runtime: 'nodejs18.x'
MemorySize: 128
Timeout: 30
Role: !GetAtt 'RoleSendDriftNotification.Arn'
Expand All @@ -549,8 +550,8 @@ Resources:
ZipFile: |
'use strict';
const querystring = require('querystring');
const AWS = require('aws-sdk')
const sns = new AWS.SNS({apiVersion: '2010-03-31'});
const { SNSClient, PublishCommand } = require('@aws-sdk/client-sns');
const sns = new SNSClient({apiVersion: '2010-03-31'});
exports.handler = async (event, context) => {
const url = `https://console.aws.amazon.com/cloudformation/home?region=${process.env.REGION}#/stacks/drifts?stackId=${querystring.escape(event.stackArn)}`;
const msg = {
Expand All @@ -560,7 +561,7 @@ Resources:
Message: `CloudFormation drift detected, stage changed from ${event.previousDriftStatus} to ${event.latestDriftStatus}.`,
'Quick Links': url
}
await sns.publish({
await sns.send(new PublishCommand({
TopicArn: process.env.TOPIC_ARN,
Message: JSON.stringify(msg),
MessageAttributes: {
Expand All @@ -569,7 +570,7 @@ Resources:
StringValue: event.stackArn
}
}
}).promise();
}));
return event;
};
LogGroupSendDriftNotification:
Expand All @@ -586,4 +587,4 @@ Outputs:
Value: 'marbot-cloudformation-drift'
StackVersion:
Description: 'Stack version.'
Value: '1.5.0'
Value: '1.6.0'
12 changes: 6 additions & 6 deletions marbot-ec2-instance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -445,9 +445,9 @@ Resources:
ZipFile: |
'use strict';
const https = require('https');
const AWS = require('aws-sdk');
const response = require('cfn-response');
const ec2 = new AWS.EC2({apiVersion: '2016-11-15'});
const { EC2Client, DescribeInstancesCommand } = require('@aws-sdk/client-ec2');
const ec2 = new EC2Client({apiVersion: '2016-11-15'});
function getData(cb) {
https.get('https://s3-eu-west-1.amazonaws.com/monitoring-jump-start/data/network.json', (res) => {
if (res.statusCode === 200) {
Expand Down Expand Up @@ -482,9 +482,9 @@ Resources:
console.log(`Error: ${JSON.stringify(err)}`);
response.send(event, context, response.FAILED, {});
} else {
ec2.describeInstances({
ec2.send(new DescribeInstancesCommand({
InstanceIds: [event.ResourceProperties.InstanceId]
}, (err, instanceData) => {
}), (err, instanceData) => {
if (err) {
console.log(`Error: ${JSON.stringify(err)}`);
response.send(event, context, response.FAILED, {});
Expand Down Expand Up @@ -522,7 +522,7 @@ Resources:
Handler: 'index.handler'
MemorySize: 128
Role: !GetAtt 'LambdaRole.Arn'
Runtime: 'nodejs16.x'
Runtime: 'nodejs18.x'
Timeout: 60
LambdaLogGroup:
Type: 'AWS::Logs::LogGroup'
Expand All @@ -538,4 +538,4 @@ Outputs:
Value: 'marbot-ec2-instance'
StackVersion:
Description: 'Stack version.'
Value: '2.5.0'
Value: '2.6.0'
10 changes: 5 additions & 5 deletions marbot-ec2-instances.yml
Original file line number Diff line number Diff line change
Expand Up @@ -370,9 +370,9 @@ Resources:
ZipFile: |
'use strict';
const https = require('https');
const AWS = require('aws-sdk');
const response = require('cfn-response');
const ec2 = new AWS.EC2({apiVersion: '2016-11-15'});
const { EC2Client, DescribeInstancesCommand } = require('@aws-sdk/client-ec2');
const ec2 = new EC2Client({apiVersion: '2016-11-15'});
function getData(cb) {
https.get('https://s3-eu-west-1.amazonaws.com/monitoring-jump-start/data/network.json', (res) => {
if (res.statusCode === 200) {
Expand Down Expand Up @@ -407,7 +407,7 @@ Resources:
console.log(`Error: ${JSON.stringify(err)}`);
response.send(event, context, response.FAILED, {});
} else {
ec2.describeInstances({
ec2.send(new DescribeInstancesCommand({
InstanceIds: [event.ResourceProperties.InstanceId]
}, (err, instanceData) => {
if (err) {
Expand Down Expand Up @@ -447,7 +447,7 @@ Resources:
Handler: 'index.handler'
MemorySize: 128
Role: !GetAtt 'LambdaRole.Arn'
Runtime: 'nodejs16.x'
Runtime: 'nodejs18.x'
Timeout: 60
LambdaLogGroup:
Type: 'AWS::Logs::LogGroup'
Expand All @@ -463,4 +463,4 @@ Outputs:
Value: 'marbot-ec2-instances'
StackVersion:
Description: 'Stack version.'
Value: '2.5.0'
Value: '2.6.0'
16 changes: 8 additions & 8 deletions marbot-elasticache-memcached.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ Resources:
ZipFile: |
'use strict';
const response = require('cfn-response');
const AWS = require('aws-sdk');
const elasticache = new AWS.ElastiCache({apiVersion: '2015-02-02'});
const { ElastiCacheClient, DescribeCacheClusterCommand, ModifyCacheClusterCommand } = require('@aws-sdk/client-elasticache');
const elasticache = new ElastiCacheClient({apiVersion: '2015-02-02'});
exports.handler = (event, context, cb) => {
console.log(JSON.stringify(event));
const failed = (err) => {
Expand All @@ -237,9 +237,9 @@ Resources:
}
};
const describe = (cacheClusterId, cb) => {
elasticache.describeCacheClusters({
elasticache.send(new DescribeCacheClusterCommand({
CacheClusterId: cacheClusterId,
}, function(err, data) {
}), function(err, data) {
if (err) {
failed(err);
} else {
Expand All @@ -254,12 +254,12 @@ Resources:
});
};
const modify = (cacheClusterId, notificationTopicArn, notificationTopicStatus, cb) => {
elasticache.modifyCacheCluster({
elasticache.send(new ModifyCacheClusterCommand({
CacheClusterId: cacheClusterId,
ApplyImmediately: true,
NotificationTopicArn: notificationTopicArn,
NotificationTopicStatus: notificationTopicStatus
}, function(err, data) {
}), function(err, data) {
if (err) {
failed(err);
} else {
Expand Down Expand Up @@ -318,7 +318,7 @@ Resources:
Handler: 'index.handler'
MemorySize: 128
Role: !GetAtt 'CustomNotificationTopicConfigurationRole.Arn'
Runtime: 'nodejs16.x'
Runtime: 'nodejs18.x'
Timeout: 10
CustomNotificationTopicConfigurationRole:
Type: 'AWS::IAM::Role'
Expand Down Expand Up @@ -350,4 +350,4 @@ Outputs:
Value: 'marbot-elasticache-memcached'
StackVersion:
Description: 'Stack version.'
Value: '1.6.0'
Value: '1.7.0'
12 changes: 6 additions & 6 deletions marbot-interface-endpoint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -276,17 +276,17 @@ Resources:
Code:
ZipFile: |
'use strict';
const AWS = require('aws-sdk');
const response = require('cfn-response');
const ec2 = new AWS.EC2({apiVersion: '2016-11-15'});
const { EC2Client, DescribeVpcEndpointsCommand } = require('@aws-sdk/client-ec2');
const ec2 = new EC2Client({apiVersion: '2016-11-15'});
exports.handler = (event, context) => {
console.log(`Invoke: ${JSON.stringify(event)}`);
if (event.RequestType === 'Delete') {
response.send(event, context, response.SUCCESS, {});
} else if (event.RequestType === 'Create' || event.RequestType === 'Update') {
ec2.describeVpcEndpoints({
ec2.send(new DescribeVpcEndpointsCommand({
VpcEndpointIds: [event.ResourceProperties.EndpointId]
}, (err, data) => {
}), (err, data) => {
if (err) {
console.log(`Error: ${JSON.stringify(err)}`);
response.send(event, context, response.FAILED, {});
Expand All @@ -304,7 +304,7 @@ Resources:
Handler: 'index.handler'
MemorySize: 128
Role: !GetAtt 'LambdaRole.Arn'
Runtime: 'nodejs16.x'
Runtime: 'nodejs18.x'
Timeout: 60
LambdaLogGroup:
Type: 'AWS::Logs::LogGroup'
Expand All @@ -320,4 +320,4 @@ Outputs:
Value: 'marbot-interface-endpoint'
StackVersion:
Description: 'Stack version.'
Value: '1.0.0'
Value: '1.1.0'
Loading

0 comments on commit 4a5316f

Please sign in to comment.