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

Commit

Permalink
upgrading to aws-sdk v3
Browse files Browse the repository at this point in the history
  • Loading branch information
rayjanoka committed Sep 11, 2023
1 parent 8c8e519 commit ff43aa5
Show file tree
Hide file tree
Showing 36 changed files with 94 additions and 76 deletions.
3 changes: 1 addition & 2 deletions deploy_autotag.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ function build-package () {
npm run compile

cp package.json lib/
npm install --prefix lib/ --production
# rm -rf lib/node_modules/aws-sdk
npm install --no-optional --omit=dev --prefix lib/

(
cd lib
Expand Down
19 changes: 18 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,27 @@
"main": "autotag.js",
"private": true,
"dependencies": {
"aws-sdk": "^2.493.0",
"babel-polyfill": "^6.7.4",
"lodash": "^4.17.14"
},
"optionalDependencies": {
"@aws-sdk/client-auto-scaling": "^3.410.0",
"@aws-sdk/client-cloudwatch": "^3.410.0",
"@aws-sdk/client-cloudwatch-events": "^3.410.0",
"@aws-sdk/client-cloudwatch-logs": "^3.410.0",
"@aws-sdk/client-data-pipeline": "^3.410.0",
"@aws-sdk/client-dynamodb": "^3.410.0",
"@aws-sdk/client-ec2": "^3.410.0",
"@aws-sdk/client-elastic-load-balancing": "^3.410.0",
"@aws-sdk/client-elastic-load-balancing-v2": "^3.410.0",
"@aws-sdk/client-emr": "^3.410.0",
"@aws-sdk/client-iam": "^3.410.0",
"@aws-sdk/client-lambda": "^3.410.0",
"@aws-sdk/client-opsworks": "^3.410.0",
"@aws-sdk/client-rds": "^3.410.0",
"@aws-sdk/client-s3": "^3.410.0",
"@aws-sdk/client-sts": "^3.410.0"
},
"devDependencies": {
"@babel/cli": "^7.5.0",
"@babel/core": "^7.5.4",
Expand Down
4 changes: 2 additions & 2 deletions src/aws_cloud_trail_log_listener.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import zlib from 'zlib.js';
import AWS from 'aws-sdk.js';
import { S3 } from "@aws-sdk/client-s3";
import each from 'lodash/each.js';
import constants from './cloud_trail_event_config.js';
import AutotagFactory from './autotag_factory.js';
Expand All @@ -10,7 +10,7 @@ class AwsCloudTrailLogListener {
this.cloudtrailEvent = cloudtrailEvent;
this.applicationContext = applicationContext;
this.enabledServices = enabledServices;
this.s3 = new AWS.S3();
this.s3 = new S3();
this.s3Region = '';
}

Expand Down
4 changes: 2 additions & 2 deletions src/workers/autotag_ami_worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AWS from 'aws-sdk';
import { EC2 } from "@aws-sdk/client-ec2";
import AutotagEC2Worker from './autotag_ec2_worker.js';

class AutotagAMIWorker extends AutotagEC2Worker {
Expand All @@ -12,7 +12,7 @@ class AutotagAMIWorker extends AutotagEC2Worker {
const resourceIds = [];
const roleName = this.roleName;
const credentials = await this.assumeRole(roleName);
this.ec2 = new AWS.EC2({
this.ec2 = new EC2({
region: this.event.awsRegion,
credentials
});
Expand Down
4 changes: 2 additions & 2 deletions src/workers/autotag_autoscale_worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AWS from 'aws-sdk';
import { AutoScaling } from "@aws-sdk/client-auto-scaling";
import AutotagDefaultWorker from './autotag_default_worker.js';

class AutotagAutoscaleWorker extends AutotagDefaultWorker {
Expand All @@ -11,7 +11,7 @@ class AutotagAutoscaleWorker extends AutotagDefaultWorker {
async tagResource() {
const roleName = this.roleName;
const credentials = await this.assumeRole(roleName);
this.autoscaling = new AWS.AutoScaling({
this.autoscaling = new AutoScaling({
region: this.event.awsRegion,
credentials
});
Expand Down
4 changes: 2 additions & 2 deletions src/workers/autotag_customer_gateway_worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AWS from 'aws-sdk';
import { EC2 } from "@aws-sdk/client-ec2";
import AutotagEC2Worker from './autotag_ec2_worker.js';

class AutotagCustomerGatewayWorker extends AutotagEC2Worker {
Expand All @@ -11,7 +11,7 @@ class AutotagCustomerGatewayWorker extends AutotagEC2Worker {
async tagResource() {
const roleName = this.roleName;
const credentials = await this.assumeRole(roleName);
this.ec2 = new AWS.EC2({
this.ec2 = new EC2({
region: this.event.awsRegion,
credentials
});
Expand Down
4 changes: 2 additions & 2 deletions src/workers/autotag_cw_alarm_worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AWS from 'aws-sdk';
import { CloudWatch } from "@aws-sdk/client-cloudwatch";
import AutotagDefaultWorker from './autotag_default_worker.js';

class AutotagCloudwatchAlarmWorker extends AutotagDefaultWorker {
Expand All @@ -11,7 +11,7 @@ class AutotagCloudwatchAlarmWorker extends AutotagDefaultWorker {
async tagResource() {
const roleName = this.roleName;
const credentials = await this.assumeRole(roleName);
this.cloudwatch = new AWS.CloudWatch({
this.cloudwatch = new CloudWatch({
region: this.event.awsRegion,
credentials
});
Expand Down
4 changes: 2 additions & 2 deletions src/workers/autotag_cw_events_rule_worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AWS from 'aws-sdk';
import { CloudWatchEvents } from "@aws-sdk/client-cloudwatch-events";
import AutotagDefaultWorker from './autotag_default_worker.js';

class AutotagCloudwatchEventsRuleWorker extends AutotagDefaultWorker {
Expand All @@ -11,7 +11,7 @@ class AutotagCloudwatchEventsRuleWorker extends AutotagDefaultWorker {
async tagResource() {
const roleName = this.roleName;
const credentials = await this.assumeRole(roleName);
this.cloudwatchEvents = new AWS.CloudWatchEvents({
this.cloudwatchEvents = new CloudWatchEvents({
region: this.event.awsRegion,
credentials
});
Expand Down
4 changes: 2 additions & 2 deletions src/workers/autotag_cw_loggroup_worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AWS from 'aws-sdk';
import { CloudWatchLogs } from "@aws-sdk/client-cloudwatch-logs";
import AutotagDefaultWorker from './autotag_default_worker.js';

class AutotagCloudwatchLogGroupWorker extends AutotagDefaultWorker {
Expand All @@ -11,7 +11,7 @@ class AutotagCloudwatchLogGroupWorker extends AutotagDefaultWorker {
async tagResource() {
const roleName = this.roleName;
const credentials = await this.assumeRole(roleName);
this.cloudwatchLogs = new AWS.CloudWatchLogs({
this.cloudwatchLogs = new CloudWatchLogs({
region: this.event.awsRegion,
credentials
});
Expand Down
4 changes: 2 additions & 2 deletions src/workers/autotag_data_pipeline_worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AWS from 'aws-sdk';
import { DataPipeline } from "@aws-sdk/client-data-pipeline";
import AutotagDefaultWorker from './autotag_default_worker.js';

class AutotagDataPipelineWorker extends AutotagDefaultWorker {
Expand All @@ -11,7 +11,7 @@ class AutotagDataPipelineWorker extends AutotagDefaultWorker {
async tagResource() {
const roleName = this.roleName;
const credentials = await this.assumeRole(roleName);
this.dataPipeline = new AWS.DataPipeline({
this.dataPipeline = new DataPipeline({
region: this.event.awsRegion,
credentials
});
Expand Down
5 changes: 2 additions & 3 deletions src/workers/autotag_default_worker.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import get from 'lodash/get.js';
import * as AWS from 'aws-sdk';
import { STS } from "@aws-sdk/client-sts";
import SETTINGS from '../autotag_settings.js';

export const AUTOTAG_TAG_NAME_PREFIX = 'AutoTag_';
Expand Down Expand Up @@ -45,10 +45,9 @@ class AutotagDefaultWorker {
assumeRole(roleName) {
return new Promise((resolve, reject) => {
try {
AWS.config.region = 'us-east-1';
//Uncomment line below for AWS STS logging
//AWS.config.logger = console;
const sts = new AWS.STS();
const sts = new STS();
sts.assumeRole({
RoleArn: this.getAssumeRoleArn(roleName),
RoleSessionName: `AutoTag-${(new Date()).getTime()}`,
Expand Down
4 changes: 2 additions & 2 deletions src/workers/autotag_dhcp_options_worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AWS from 'aws-sdk';
import { EC2 } from "@aws-sdk/client-ec2";
import AutotagEC2Worker from './autotag_ec2_worker.js';

class AutotagDhcpOptionsWorker extends AutotagEC2Worker {
Expand All @@ -11,7 +11,7 @@ class AutotagDhcpOptionsWorker extends AutotagEC2Worker {
async tagResource() {
const roleName = this.roleName;
const credentials = await this.assumeRole(roleName);
this.ec2 = new AWS.EC2({
this.ec2 = new EC2({
region: this.event.awsRegion,
credentials
});
Expand Down
4 changes: 2 additions & 2 deletions src/workers/autotag_dynamodb_worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AWS from 'aws-sdk';
import { DynamoDB } from "@aws-sdk/client-dynamodb";
import AutotagDefaultWorker from './autotag_default_worker.js';

class AutotagDynamoDBWorker extends AutotagDefaultWorker {
Expand All @@ -11,7 +11,7 @@ class AutotagDynamoDBWorker extends AutotagDefaultWorker {
async tagResource() {
const roleName = this.roleName;
const credentials = await this.assumeRole(roleName);
this.dynamoDB = new AWS.DynamoDB({
this.dynamoDB = new DynamoDB({
region: this.event.awsRegion,
credentials
});
Expand Down
4 changes: 2 additions & 2 deletions src/workers/autotag_ebs_worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AWS from 'aws-sdk';
import { EC2 } from "@aws-sdk/client-ec2";
import AutotagEC2Worker from './autotag_ec2_worker.js';

class AutotagEBSWorker extends AutotagEC2Worker {
Expand All @@ -11,7 +11,7 @@ class AutotagEBSWorker extends AutotagEC2Worker {
async tagResource() {
const roleName = this.roleName;
const credentials = await this.assumeRole(roleName);
this.ec2 = new AWS.EC2({
this.ec2 = new EC2({
region: this.event.awsRegion,
credentials
});
Expand Down
12 changes: 7 additions & 5 deletions src/workers/autotag_ec2_worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import AWS from 'aws-sdk';
import { AutoScaling } from "@aws-sdk/client-auto-scaling";
import { EC2 } from "@aws-sdk/client-ec2";
import { OpsWorks } from "@aws-sdk/client-opsworks";
import AutotagDefaultWorker from './autotag_default_worker.js';

class AutotagEC2Worker extends AutotagDefaultWorker {
Expand All @@ -14,13 +16,13 @@ class AutotagEC2Worker extends AutotagDefaultWorker {
let parentTags;
let opsworksInstances;

this.ec2 = new AWS.EC2({
this.ec2 = new EC2({
region: this.event.awsRegion,
credentials
});

if (this.isInvokedByAutoscaling()) {
this.autoscaling = new AWS.AutoScaling({
this.autoscaling = new AutoScaling({
region: this.event.awsRegion,
credentials
});
Expand All @@ -30,7 +32,7 @@ class AutotagEC2Worker extends AutotagDefaultWorker {
}

if (this.isInvokedByOpsworks()) {
this.opsworks = new AWS.OpsWorks({
this.opsworks = new OpsWorks({
region: this.event.awsRegion,
credentials
});
Expand All @@ -39,7 +41,7 @@ class AutotagEC2Worker extends AutotagDefaultWorker {
} catch (err) {
if (err.name === 'ResourceNotFoundException') {
// switch to the main OpsWorks region and try again
this.opsworks = new AWS.OpsWorks({
this.opsworks = new OpsWorks({
region: 'us-east-1',
credentials
});
Expand Down
4 changes: 2 additions & 2 deletions src/workers/autotag_eip_worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AWS from 'aws-sdk';
import { EC2 } from "@aws-sdk/client-ec2";
import AutotagEC2Worker from './autotag_ec2_worker.js';

class AutotagEIPWorker extends AutotagEC2Worker {
Expand All @@ -11,7 +11,7 @@ class AutotagEIPWorker extends AutotagEC2Worker {
async tagResource() {
const roleName = this.roleName;
const credentials = await this.assumeRole(roleName);
this.ec2 = new AWS.EC2({
this.ec2 = new EC2({
region: this.event.awsRegion,
credentials
});
Expand Down
7 changes: 4 additions & 3 deletions src/workers/autotag_elb_worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import AWS from 'aws-sdk';
import { ElasticLoadBalancing as ELB } from "@aws-sdk/client-elastic-load-balancing";
import { ElasticLoadBalancingV2 as ELBv2 } from "@aws-sdk/client-elastic-load-balancing-v2";
import AutotagDefaultWorker from './autotag_default_worker.js';

class AutotagELBWorker extends AutotagDefaultWorker {
Expand All @@ -12,13 +13,13 @@ class AutotagELBWorker extends AutotagDefaultWorker {
const roleName = this.roleName;
const credentials = await this.assumeRole(roleName);
if (this.isLoadBalancerV2()) {
this.elbv2 = new AWS.ELBv2({
this.elbv2 = new ELBv2({
region: this.event.awsRegion,
credentials
});
await this.tagELBV2Resource();
} else {
this.elb = new AWS.ELB({
this.elb = new ELB({
region: this.event.awsRegion,
credentials
});
Expand Down
4 changes: 2 additions & 2 deletions src/workers/autotag_emr_worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AWS from 'aws-sdk';
import { EMR } from "@aws-sdk/client-emr";
import AutotagDefaultWorker from './autotag_default_worker.js';

class AutotagEMRWorker extends AutotagDefaultWorker {
Expand All @@ -11,7 +11,7 @@ class AutotagEMRWorker extends AutotagDefaultWorker {
async tagResource() {
const roleName = this.roleName;
const credentials = await this.assumeRole(roleName);
this.emr = new AWS.EMR({
this.emr = new EMR({
region: this.event.awsRegion,
credentials
});
Expand Down
4 changes: 2 additions & 2 deletions src/workers/autotag_eni_worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AWS from 'aws-sdk';
import { EC2 } from "@aws-sdk/client-ec2";
import AutotagEC2Worker from './autotag_ec2_worker.js';

class AutotagENIWorker extends AutotagEC2Worker {
Expand All @@ -11,7 +11,7 @@ class AutotagENIWorker extends AutotagEC2Worker {
async tagResource() {
const roleName = this.roleName;
const credentials = await this.assumeRole(roleName);
this.ec2 = new AWS.EC2({
this.ec2 = new EC2({
region: this.event.awsRegion,
credentials
});
Expand Down
4 changes: 2 additions & 2 deletions src/workers/autotag_iam_role_worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AWS from 'aws-sdk';
import { IAM } from "@aws-sdk/client-iam";
import AutotagDefaultWorker from './autotag_default_worker.js';

class AutotagIAMRoleWorker extends AutotagDefaultWorker {
Expand All @@ -11,7 +11,7 @@ class AutotagIAMRoleWorker extends AutotagDefaultWorker {
async tagResource() {
const roleName = this.roleName;
const credentials = await this.assumeRole(roleName);
this.iam = new AWS.IAM({
this.iam = new IAM({
region: this.event.awsRegion,
credentials
});
Expand Down
4 changes: 2 additions & 2 deletions src/workers/autotag_iam_user_worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AWS from 'aws-sdk';
import { IAM } from "@aws-sdk/client-iam";
import AutotagDefaultWorker from './autotag_default_worker.js';

class AutotagIAMUserWorker extends AutotagDefaultWorker {
Expand All @@ -11,7 +11,7 @@ class AutotagIAMUserWorker extends AutotagDefaultWorker {
async tagResource() {
const roleName = this.roleName;
const credentials = await this.assumeRole(roleName);
this.iam = new AWS.IAM({
this.iam = new IAM({
region: this.event.awsRegion,
credentials
});
Expand Down
4 changes: 2 additions & 2 deletions src/workers/autotag_internet_gateway_worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AWS from 'aws-sdk';
import { EC2 } from "@aws-sdk/client-ec2";
import AutotagEC2Worker from './autotag_ec2_worker.js';

class AutotagInternetGatewayWorker extends AutotagEC2Worker {
Expand All @@ -11,7 +11,7 @@ class AutotagInternetGatewayWorker extends AutotagEC2Worker {
async tagResource() {
const roleName = this.roleName;
const credentials = await this.assumeRole(roleName);
this.ec2 = new AWS.EC2({
this.ec2 = new EC2({
region: this.event.awsRegion,
credentials
});
Expand Down
4 changes: 2 additions & 2 deletions src/workers/autotag_lambda_function_worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import AWS from 'aws-sdk';
import { Lambda } from "@aws-sdk/client-lambda";
import AutotagDefaultWorker from './autotag_default_worker.js';

class AutotagLambdaFunctionWorker extends AutotagDefaultWorker {
Expand All @@ -11,7 +11,7 @@ class AutotagLambdaFunctionWorker extends AutotagDefaultWorker {
async tagResource() {
const roleName = this.roleName;
const credentials = await this.assumeRole(roleName);
this.lambda = new AWS.Lambda({
this.lambda = new Lambda({
region: this.event.awsRegion,
credentials
});
Expand Down
Loading

0 comments on commit ff43aa5

Please sign in to comment.