Skip to content

Commit

Permalink
feat!: upgrade to AWS SDK v3
Browse files Browse the repository at this point in the history
BREAKING CHANGE: drop support for aws-sdk v2
  • Loading branch information
jedwards1211 committed Jun 10, 2024
1 parent 731de41 commit 6d8cdb1
Show file tree
Hide file tree
Showing 7 changed files with 4,868 additions and 8,248 deletions.
20 changes: 14 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
if (process.env.AWS_SDK_LOAD_CONFIG == null)
process.env.AWS_SDK_LOAD_CONFIG = '1'

const AWS = require('aws-sdk')
const { EC2Client, DescribeImagesCommand } = require('@aws-sdk/client-ec2')
const {
SSMClient,
DescribeInstanceInformationCommand,
} = require('@aws-sdk/client-ssm')
const { selectEC2Instance } = require('@jcoreio/aws-select-cli-prompts')
const { spawn } = require('child_process')
const os = require('os')
Expand All @@ -14,7 +18,9 @@ const path = require('path')
const { promisify } = require('util')

async function getAmiName(ec2, ImageId) {
const { Images } = await ec2.describeImages({ ImageIds: [ImageId] }).promise()
const { Images } = await ec2.send(
new DescribeImagesCommand({ ImageIds: [ImageId] })
)
const name = Images && Images[0] && Images[0].Name
if (!name) throw new Error(`failed to get name for image: ${ImageId}`)
return name
Expand Down Expand Up @@ -55,7 +61,7 @@ function signalCode(signal) {
return 0
}

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

if (InstanceId) {
const { InstanceInformationList: [{ PlatformName } = {}] = [] } = await ssm
.describeInstanceInformation({
const {
InstanceInformationList: [{ PlatformName } = {}] = [],
} = await ssm.send(
new DescribeInstanceInformationCommand({
Filters: [{ Key: 'InstanceIds', Values: [InstanceId] }],
})
.promise()
)
if (PlatformName) {
const userFromPlatform = getUser(PlatformName)
if (userFromPlatform !== 'ec2-user') user = userFromPlatform
Expand Down
10 changes: 3 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,18 @@
"@commitlint/config-conventional": "^11.0.0",
"@jedwards1211/commitlint-config": "^1.0.1",
"@jedwards1211/eslint-config": "^2.0.0",
"chai": "^4.1.2",
"codecov": "^3.7.2",
"cross-env": "^5.2.0",
"eslint": "^7.10.0",
"eslint-config-prettier": "^6.12.0",
"husky": "^4.3.0",
"istanbul": "^0.4.5",
"lint-staged": "^10.4.0",
"mocha": "^6.2.1",
"nyc": "^11.4.1",
"prettier": "^1.15.1",
"prettier-eslint": "^8.8.2",
"semantic-release": "^17.1.2"
},
"dependencies": {
"@jcoreio/aws-select-cli-prompts": "^1.1.0",
"aws-sdk": "^2.829.0"
"@aws-sdk/client-ec2": "^3.592.0",
"@aws-sdk/client-ssm": "^3.592.0",
"@jcoreio/aws-select-cli-prompts": "^2.0.3"
}
}
Loading

0 comments on commit 6d8cdb1

Please sign in to comment.