LoginSignup
7
7

More than 5 years have passed since last update.

機密情報をLambdaで使いたいとき

Posted at

AWS Systems Manager パラメータストアを使いましょう。

ソースコードに書きたくない、環境変数にも残したくない。そういったときにパラメータストアが役に立ちます。

パラメータストアでは暗号化もサポートしているので、機密情報はこれを使って保存します。

パラメータストア自体の使い方はGUIからできるので省略しますが、Lambda(Python)では次のような感じでサクッと利用することができます。

ssm = boto3.client('ssm')
ssm_response = ssm.get_parameters(
  Names = [
    (パラメータストアキー名),
  ],
  WithDecryption=True
)
print(ssm_response['Parameters'][0]['Value'])

IAMポリシーはこんな感じです。

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Action": [
                "ssm:GetParameters"
            ],
            "Resource": [
                "arn:aws:ssm:*:*:parameter/(パラメータストアキー名)"
            ],
            "Effect": "Allow"
        }
    ]
}
7
7
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
7
7