55if ( 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' )
913const { selectEC2Instance } = require ( '@jcoreio/aws-select-cli-prompts' )
1014const { spawn } = require ( 'child_process' )
1115const os = require ( 'os' )
@@ -14,7 +18,9 @@ const path = require('path')
1418const { promisify } = require ( 'util' )
1519
1620async 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
0 commit comments