使用 aws-cli 将 url 保存到 AWS 参数存储
Saving a url to AWS parameter store with aws-cli
好的,所以我正在尝试以编程方式将无服务器生成的 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
但是,如果我将 URL 括在引号中...
aws ssm put-parameter --name /dev/someStore --value "https://google.com" --type String
它仍然失败并出现同样的错误。有什么方法可以阻止 cli 尝试评估 URL 并只保存该死的字符串?
发生这种情况是因为 questionable behavior by awscli v1. When it sees a URL, it invokes an HTTP GET for a result. This does not happen in awscli v2。
您可以按如下方式解决此问题:
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 上报告。
实现此功能的另一个选择是不在值中包含 https 协议,只包含域名或路径。检索后添加适当的协议。有时我们想使用 https 或 http 甚至 ssh。以 git url 为例。用于访问具有适当端口的资源的多种协议,其中路径是所需的值
由@jarmod 链接的关于此主题的 GitHub 讨论也有另一种解决方案。我会在这里复制它以供其他人使用,以避免扫描整个线程。
将以下内容与现有的任何其他设置一起添加到您的 ~/.aws/config
。
[default]
cli_follow_urlparam = false
P.S。似乎在 "Loading Parameters from a File" 部分的 the AWS documentation 中也提到了它。
默认情况下,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
}
为了补充@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}"
好的,所以我正在尝试以编程方式将无服务器生成的 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
但是,如果我将 URL 括在引号中...
aws ssm put-parameter --name /dev/someStore --value "https://google.com" --type String
它仍然失败并出现同样的错误。有什么方法可以阻止 cli 尝试评估 URL 并只保存该死的字符串?
发生这种情况是因为 questionable behavior by awscli v1. When it sees a URL, it invokes an HTTP GET for a result. This does not happen in awscli v2。
您可以按如下方式解决此问题:
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 上报告。
实现此功能的另一个选择是不在值中包含 https 协议,只包含域名或路径。检索后添加适当的协议。有时我们想使用 https 或 http 甚至 ssh。以 git url 为例。用于访问具有适当端口的资源的多种协议,其中路径是所需的值
由@jarmod 链接的关于此主题的 GitHub 讨论也有另一种解决方案。我会在这里复制它以供其他人使用,以避免扫描整个线程。
将以下内容与现有的任何其他设置一起添加到您的 ~/.aws/config
。
[default]
cli_follow_urlparam = false
P.S。似乎在 "Loading Parameters from a File" 部分的 the AWS documentation 中也提到了它。
默认情况下,AWS CLI 遵循以 https://
或 http://
开头的任何字符串参数。抓取这些URL,将下载的内容作为参数,而不是URL。
使 CLI 不会以 https://
或 http://
为前缀的字符串与普通字符串参数有任何不同 运行:
aws configure set cli_follow_urlparam false
cli_follow_urlparam
控制 CLI 是否会尝试跟踪以前缀 https://
或 http://
.
见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
}
为了补充@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}"