LoginSignup
0
0

More than 3 years have passed since last update.

[CLI] AWS System Manager のパラメータストアにハイフン始まりのテキストを登録できない

Posted at

TL;DR

  • aws-cli からパラメータストアに登録するとき、ハイフンが最初についてる値は失敗した
  • マネジメントコンソールからは問題なく設定できた

経緯

AWS System Manager 内のパラメータストアはcliが使えます。
今回はput-parameterがうまく行かなかったのでメモ書きです。

以下のバージョンを使用しています。

% aws --version
aws-cli/2.1.33 Python/3.8.8 Darwin/19.6.0 exe/x86_64 prompt/off

通常のパターン

AWSのパラメータストアに name=foo, value=bar のテキストを登録します。これは問題なし。

% aws ssm put-parameter --name "foo" --value "bar" --type "String"      
{
    "Version": 1,
    "Tier": "Standard"
}
% aws ssm get-parameter --name "foo"                              
{
    "Parameter": {
        "Name": "foo",
        "Type": "String",
        "Value": "bar",
        "Version": 1,
        "LastModifiedDate": "2021-05-07T21:26:04.671000+09:00",
        "ARN": "arn:aws:ssm:ap-northeast-1:ACCOUNT_ID:parameter/foo",
        "DataType": "text"
    }
}
% aws ssm delete-parameter --name "foo"      
%                      

ダメだったパターン

この value=barvalue=-bar としてみると、失敗してしまいます。

% aws ssm put-parameter --name "foo" --value "-bar" --type "String"

usage: aws [options] <command> <subcommand> [<subcommand> ...] [parameters]
To see help text, you can run:

  aws help
  aws <command> help
  aws <command> <subcommand> help

aws: error: argument --value: expected one argument

value=\-bar として登録したら、しっかりとエスケープしてくれます(そうじゃない)

aws ssm put-parameter --name "foo" --value "\-bar" --type "String"
{
    "Version": 1,
    "Tier": "Standard"
}
% aws ssm get-parameter --name "foo"                             
{
    "Parameter": {
        "Name": "foo",
        "Type": "String",
        "Value": "\\-bar",
        "Version": 1,
        "LastModifiedDate": "2021-05-07T21:31:32.513000+09:00",
        "ARN": "arn:aws:ssm:ap-northeast-1:ACCOUNT_ID:parameter/foo",
        "DataType": "text"
    }
}

対応

マネジメントコンソールから手動で設定することは可能でした。

% aws ssm get-parameter --name "foo"   
{
    "Parameter": {
        "Name": "foo",
        "Type": "String",
        "Value": "-bar",
        "Version": 1,
        "LastModifiedDate": "2021-05-07T21:39:54.401000+09:00",
        "ARN": "arn:aws:ssm:ap-northeast-1:ACCOUNT_ID:parameter/foo",
        "DataType": "text"
    }
}
0
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
0
0