Skip to content

Instantly share code, notes, and snippets.

@noid11
Last active December 23, 2020 21:39
Show Gist options
  • Save noid11/0b0dd283f57ba615791541c8b43ea1f3 to your computer and use it in GitHub Desktop.
Save noid11/0b0dd283f57ba615791541c8b43ea1f3 to your computer and use it in GitHub Desktop.
AWS SDK for JavaScript v3 を typescript でサクッと動かす

これは何?

  • AWS SDK for JavaScript の version 3 が GA した
  • version 3 は First-class TypeScript support しているものの TypeScript での使い方についてはサンプルを発見で着たかったので自分なりに試したメモ

セットアップ

npm init -y
npm install --save-dev typescript ts-node @types/node
npx tsc --init

コーディング

  • ファイル名は app.ts とする
import { DescribeRegionsCommand, EC2Client } from '@aws-sdk/client-ec2'

const REGION = 'ap-northeast-1'
const ec2client = new EC2Client(REGION)

const run = async () => {
    try {
        const data = await ec2client.send(new DescribeRegionsCommand({}))
        console.log(data)
    } catch (err) {
        console.log(err)
    }
}

run()

実行

npx ts-node app.ts

環境

% node -v
v12.16.1
% npm -v
6.14.8

Ref

What is the AWS SDK for JavaScript? - AWS SDK for JavaScript
https://docs.aws.amazon.com/sdk-for-javascript/v3/developer-guide/welcome.html

AWS SDK for JavaScript v3
https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/index.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment