Help us understand the problem. What is going on with this article?

【Node.js】AWS SSMパラメータストアの値を取得する

関連

使用するモジュール

  • aws-sdk
    公式で提供されているライブラリ
npm i aws-sdk

サンプルコード

今回はAWS SSM パラメータストアに以下のようなパラメータが作成してある。

パラメータ名
sample-parameter HOGEHOGE!!
const AWS = require('aws-sdk');

const main = async () => {
    // 認証情報
    // `~/.aws/credentials`に認証情報が設定されている場合、
    // または環境変数`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`に認証情報が設定されている場合は
    // `access_key_id`と`secret_access_key`は不要
    const credentials = {
        accessKeyId: 'xxxxxxxxxxxxxxxxxxxx',
        secretAccessKey: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
        region: 'ap-northeast-1'
    };

    // SSMクライアントを作成
    const ssm = new AWS.SSM(credentials);

    // リクエスト
    const request = {
        Name: 'sample-parameter', // パラメータ名
        WithDecryption: true      // 暗号化されている場合は復号し、暗号化されていない場合は何もしない
    };
    const response = await ssm.getParameter(request).promise();

    console.log(response);
    // => { Parameter:
    //      { Name: 'sample-parameter',
    //        Type: 'SecureString',
    //        Value: 'HOGEHOGE!!',
    //        Version: 1,
    //        LastModifiedDate: 2019-09-12T15:28:02.134Z,
    //        ARN:
    //         'arn:aws:ssm:ap-northeast-1:xxxxxxxxxxxx:parameter/sample-parameter' } }

    console.log(response.Parameter.Value);
    // => HOGEHOGE!!
};
main();

参考

Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away