0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

nodejsでパラメータストアの値をいい感じに取り出す方法

Posted at

SSMのgetSSMParametersを使って複数のパラメータを取得する時、ちょっとごにょごにょしなくちゃいけないんですが、思ったよりキレイなコードになったので、lambdaのサンプルコードを載せておきます。

const AWS = require("aws-sdk");
AWS.config.update({ region: "ap-northeast-1" });
const SSM = new AWS.SSM();

const getSSMParameters = async(names) => {
    const result = await SSM.getParameters({Names: names}).promise();
    return names.map(name => 
        result?.Parameters?.find(el => el.Name === name)?.Value
    );
};

exports.handler = async (event) => {
    const [url, stranger, user, nickname, avatar] = await getSSMParameters(['url','stranger','user','nickname','avatar']);
    const response = {
        statusCode: 200,
        body: {url, stranger, user, nickname, avatar},
    };
    return response;
};
0
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?