好的,所以我试图以编程方式将无服务器生成的API终结点存储在参数存储中,以供另一个项目摄取。
仅作为示例,我将尝试存储google.com。
aws ssm put-parameter --name /dev/someStore --value https://google.com --type String
这失败了,可以理解。
Error parsing parameter '--value': Unable to retrieve https://google.com: received non 200 status code of 301
但是,如果我将网址用引号引起来...
aws ssm put-parameter --name /dev/someStore --value "https://google.com" --type String
它仍然失败,并显示相同的错误。有什么方法可以阻止cli尝试评估URL并仅保存该死的字符串吗?
答案 0 :(得分:6)
发生这种情况是由于AWSCLI的questionable behavior。看到URL时,它将调用HTTP GET作为结果。
您可以按照以下方法解决此问题:
aws ssm put-parameter --cli-input-json '{
"Name": "/dev/someStore",
"Value": "https://google.com",
"Type": "String"
}'
或者您可以将JSON存储在名为params.json的文件中并调用:
aws ssm put-parameter --cli-input-json file://params.json
您可以在aws/aws-cli/issues/2507跟踪根本问题。
答案 1 :(得分:2)
另一个可行的方法是在值中不包含https协议,而仅在域名或路径中包含。检索后,添加适当的协议。有时我们想使用https或http甚至ssh。以git url为例。通过适当的端口访问资源的多种协议,其中路径是所需的值
答案 2 :(得分:2)
通过@jarmod链接的关于该主题的GitHub讨论也有另一种解决方案。我将在这里将其复制给其他人,以免扫描整个线程。
将以下内容以及存在的任何其他设置添加到您的~/.aws/config
中。
[default]
cli_follow_urlparam = false
P.S。似乎在the AWS documentation的“从文件加载参数”部分中也提到了此问题。
答案 3 :(得分:1)
默认情况下,AWS CLI遵循以https://
或http://
开头的任何字符串参数。将获取这些URL,并将下载的内容用作参数而不是URL。
要使CLI不会将以https://
或http://
为前缀的字符串与普通字符串参数区别对待,请运行:
aws configure set cli_follow_urlparam false
cli_follow_urlparam
控制CLI是否尝试遵循以前缀https://
或http://
开头的参数中的URL链接。
请参见https://docs.aws.amazon.com/cli/latest/topic/config-vars.html
问题:
aws ssm put-parameter --name /config/application/some-url --value http://google.com --type String --region eu-central-1 --overwrite
Error parsing parameter '--value': Unable to retrieve http://google.com: received non 200 status code of 301
解决方案:
aws configure set cli_follow_urlparam false
aws ssm put-parameter --name /config/application/some-url --value http://google.com --type String --region eu-central-1 --overwrite
{
"Version": 1
}
答案 4 :(得分:1)
为补充@jarmod答案,以下示例显示
如何处理Overwrite
文件,bash变量中的url以及使json多行字符串。
URL='https://www.some.url.com'
json_params='{'
json_params+='"Name": "/param/path",'
json_params+='"Value": "'${URL}'",'
json_params+='"Type": "String",'
json_params+='"Overwrite": true'
json_params+='}'
aws ssm put-parameter \
--cli-input-json "${json_params}"