LoginSignup
2
1

More than 5 years have passed since last update.

AWS-SDK & nodejs メモ

Posted at

はじめに

自分用のメモ代わりです。すみません。
nodejsでaws-sdkの各種機能を適当にメモっていきます。

共通処理

aws-sdkを読み込み、リージョンとプロファイルを設定

const aws = require('aws-sdk');

var credentials = new aws.SharedIniFileCredentials({
    profile: "<プロフィル名>"
});
aws.config.update({
    region: "<リージョン名>",
    credentials: credentials
});

S3

ローカルファイルをS3にアップロード

const s3 = new aws.S3();

const params = {
    Bucket: "<バケット名>",
    Key: "<キー名>",
    Body: fs.createReadStream("<ローカルファイルのパス>"),
};

s3.upload(params).promise()
.then(function(data) {
    console.log(`アップロード成功: s3://${data.Bucket}/${data.Key}`);
})
.catch(function(err){
    console.dir(err);
});
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1