LoginSignup
1
0

AWS Systems Manager Parameter Storeを使ってみた

Posted at

AWS Systems Manager Parameter Storeとは?

設定データ管理とシークレット管理のための安全な階層型ストレージを提供します。パスワード、データベース文字列、Amazon Machine Image (AMI) ID、ライセンスコードなどのデータをパラメータ値として保存することができます
https://docs.aws.amazon.com/ja_jp/systems-manager/latest/userguide/systems-manager-parameter-store.html

ソースコードにパスワードを記載する必要がなくなります
Secrets Managerとは違いローテーション機能がありません

AWS Systems Manager Parameter Storeの設定

  1. AWS Systems Manager のページを開き、左のメニューからパラメータストアを選択

  2. パラメータの作成を選択

  3. 格納データを作成
    選択できるものは以下の3つがあるようです

  • 文字列
  • 文字列のリスト
  • 安全な文字列(AWS KMS キーを使用して暗号化してテキストを保存することが可能)
    image-1.png

パラメータ取得

コード

import boto3
from botocore.exceptions import ClientError

def get_parameter():

    parameter_name = "" # 2.で設定したパラメータの名前
    region_name = "" # Parameter Storeを作成したリージョン

    session = boto3.session.Session()
    client = session.client(
        aws_access_key_id = '', # アクセスキー
        aws_secret_access_key  = '', # シークレットキー
        service_name='ssm',
        region_name=region_name
    )

    try:
        response = client.get_parameter(
            Name=parameter_name,
        )
    except ClientError as e:
        raise e

    return response['Parameter']['Value']

print(get_parameter())

結果

test
sample

種類を文字列のリストの場合で作成した場合、取得した際に自動でリスト化などしてくれると思ったのですが、普通にカンマ区切りの文字列が返ってきただけでした
種類が文字列をカンマ区切りで登録した場合と種類が文字列のリストで登録した場合の違いがよくわからなかったです
image-2.png

結果

test,sample

終わり

種類が文字列のリストと文字列の使い分けがあれば教えてください

1
0
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
1
0