Skip to content

Commit 6d8cdb1

Browse files
committed
feat!: upgrade to AWS SDK v3
BREAKING CHANGE: drop support for aws-sdk v2
1 parent 731de41 commit 6d8cdb1

File tree

7 files changed

+4868
-8248
lines changed

7 files changed

+4868
-8248
lines changed

index.js

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
if (process.env.AWS_SDK_LOAD_CONFIG == null)
66
process.env.AWS_SDK_LOAD_CONFIG = '1'
77

8-
const AWS = require('aws-sdk')
8+
const { EC2Client, DescribeImagesCommand } = require('@aws-sdk/client-ec2')
9+
const {
10+
SSMClient,
11+
DescribeInstanceInformationCommand,
12+
} = require('@aws-sdk/client-ssm')
913
const { selectEC2Instance } = require('@jcoreio/aws-select-cli-prompts')
1014
const { spawn } = require('child_process')
1115
const os = require('os')
@@ -14,7 +18,9 @@ const path = require('path')
1418
const { promisify } = require('util')
1519

1620
async function getAmiName(ec2, ImageId) {
17-
const { Images } = await ec2.describeImages({ ImageIds: [ImageId] }).promise()
21+
const { Images } = await ec2.send(
22+
new DescribeImagesCommand({ ImageIds: [ImageId] })
23+
)
1824
const name = Images && Images[0] && Images[0].Name
1925
if (!name) throw new Error(`failed to get name for image: ${ImageId}`)
2026
return name
@@ -55,7 +61,7 @@ function signalCode(signal) {
5561
return 0
5662
}
5763

58-
async function ec2ssh({ ec2 = new AWS.EC2(), ssm = new AWS.SSM() } = {}) {
64+
async function ec2ssh({ ec2 = new EC2Client(), ssm = new SSMClient() } = {}) {
5965
const instance = await selectEC2Instance({
6066
ec2,
6167
Filters: [
@@ -80,11 +86,13 @@ async function ec2ssh({ ec2 = new AWS.EC2(), ssm = new AWS.SSM() } = {}) {
8086
let user = ImageId ? getUser(await getAmiName(ec2, ImageId)) : null
8187

8288
if (InstanceId) {
83-
const { InstanceInformationList: [{ PlatformName } = {}] = [] } = await ssm
84-
.describeInstanceInformation({
89+
const {
90+
InstanceInformationList: [{ PlatformName } = {}] = [],
91+
} = await ssm.send(
92+
new DescribeInstanceInformationCommand({
8593
Filters: [{ Key: 'InstanceIds', Values: [InstanceId] }],
8694
})
87-
.promise()
95+
)
8896
if (PlatformName) {
8997
const userFromPlatform = getUser(PlatformName)
9098
if (userFromPlatform !== 'ec2-user') user = userFromPlatform

package.json

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,18 @@
7979
"@commitlint/config-conventional": "^11.0.0",
8080
"@jedwards1211/commitlint-config": "^1.0.1",
8181
"@jedwards1211/eslint-config": "^2.0.0",
82-
"chai": "^4.1.2",
83-
"codecov": "^3.7.2",
8482
"cross-env": "^5.2.0",
8583
"eslint": "^7.10.0",
8684
"eslint-config-prettier": "^6.12.0",
8785
"husky": "^4.3.0",
88-
"istanbul": "^0.4.5",
8986
"lint-staged": "^10.4.0",
90-
"mocha": "^6.2.1",
91-
"nyc": "^11.4.1",
9287
"prettier": "^1.15.1",
9388
"prettier-eslint": "^8.8.2",
9489
"semantic-release": "^17.1.2"
9590
},
9691
"dependencies": {
97-
"@jcoreio/aws-select-cli-prompts": "^1.1.0",
98-
"aws-sdk": "^2.829.0"
92+
"@aws-sdk/client-ec2": "^3.592.0",
93+
"@aws-sdk/client-ssm": "^3.592.0",
94+
"@jcoreio/aws-select-cli-prompts": "^2.0.3"
9995
}
10096
}

0 commit comments

Comments
 (0)