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 (#64)
Browse files Browse the repository at this point in the history
* Upgrading to Node.js 18

* Small fix

* Fixing YAML format

* Upgrading cfn-lint

* Fixing versions

* Fixing ElastiCache command
  • Loading branch information
andreaswittig authored Sep 14, 2023
1 parent 2d3c2e6 commit 27bb794
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
with:
python-version: '3.8'
- run: |
pip install cfn-lint==0.61.0
pip install cfn-lint==0.79.8
yamllint *.yml
cfn-lint -t *.yml
find . -name 'marbot*.yml' | while read file; do set -ex && grep -q "LICENSE-2.0" "$file"; done;
Expand Down
51 changes: 26 additions & 25 deletions marbot-cloudformation-drift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ Resources:
{
"Type": "monitoring-jump-start-connection",
"StackTemplate": "marbot-cloudformation-drift",
"StackVersion": "1.5.0",
"StackVersion": "1.6.0",
"Partition": "${AWS::Partition}",
"AccountId": "${AWS::AccountId}",
"Region": "${AWS::Region}",
Expand Down 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');
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'
14 changes: 7 additions & 7 deletions marbot-ec2-instance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ Resources:
{
"Type": "monitoring-jump-start-connection",
"StackTemplate": "marbot-ec2-instance",
"StackVersion": "2.5.0",
"StackVersion": "2.6.0",
"Partition": "${AWS::Partition}",
"AccountId": "${AWS::AccountId}",
"Region": "${AWS::Region}",
Expand Down 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'
14 changes: 7 additions & 7 deletions marbot-ec2-instances.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ Resources:
{
"Type": "monitoring-jump-start-connection",
"StackTemplate": "marbot-ec2-instances",
"StackVersion": "2.5.0",
"StackVersion": "2.6.0",
"Partition": "${AWS::Partition}",
"AccountId": "${AWS::AccountId}",
"Region": "${AWS::Region}",
Expand Down 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,9 +407,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 @@ -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'
18 changes: 9 additions & 9 deletions marbot-elasticache-memcached.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Resources:
{
"Type": "monitoring-jump-start-connection",
"StackTemplate": "marbot-elasticache-memcached",
"StackVersion": "1.6.0",
"StackVersion": "1.7.0",
"Partition": "${AWS::Partition}",
"AccountId": "${AWS::AccountId}",
"Region": "${AWS::Region}",
Expand Down 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, DescribeCacheClustersCommand, 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 DescribeCacheClustersCommand({
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'
14 changes: 7 additions & 7 deletions marbot-interface-endpoint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ Resources:
{
"Type": "monitoring-jump-start-connection",
"StackTemplate": "marbot-interface-endpoint",
"StackVersion": "1.0.0",
"StackVersion": "1.1.0",
"Partition": "${AWS::Partition}",
"AccountId": "${AWS::AccountId}",
"Region": "${AWS::Region}",
Expand Down 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 27bb794

Please sign in to comment.