user5602665
user5602665

Reputation:

Saving a url to AWS parameter store with aws-cli

Alright, so I'm trying to programmatically store my Serverless generated API endpoint in parameter store for another project to ingest.

Just for an example, I'm going to try to store google.com.

aws ssm put-parameter --name /dev/someStore --value https://google.com --type String

This fails, understandably so.

Error parsing parameter '--value': Unable to retrieve https://google.com: received non 200 status code of 301

However, if I wrap the URL in quotes...

aws ssm put-parameter --name /dev/someStore --value "https://google.com" --type String

It still fails with the same error. Is there any way to stop the cli from trying to evaluate the URL and just save the goddamn string?

Upvotes: 15

Views: 5014

Answers (5)

jarmod
jarmod

Reputation: 78563

This is happening because of a 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.

You can work around this behavior as follows:

aws ssm put-parameter --cli-input-json '{
  "Name": "/dev/someStore",
  "Value": "https://google.com",
  "Type": "String"
}'

Or you can store the JSON in a file named params.json and invoke:

aws ssm put-parameter --cli-input-json file://params.json

The underlying issue was reported at aws/aws-cli/issues/2507.

Upvotes: 20

Marcin
Marcin

Reputation: 238051

To complement @jarmod answers, here is an example showing how one can deal with Overwrite file, url in bash variable and making the json multi-line string.

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}"

Upvotes: 1

Eugene Khyst
Eugene Khyst

Reputation: 10315

By default AWS CLI follows any string parameters that start with https:// or http://. These URLs are fetched, and the downloaded content is used as the parameter instead of URL.

To make CLI not treat strings prefixed with https:// or http:// any differently than normal string parameters run:

aws configure set cli_follow_urlparam false

cli_follow_urlparam controls whether or not the CLI will attempt to follow URL links in parameters that start with either prefix https:// or http://.

See https://docs.aws.amazon.com/cli/latest/topic/config-vars.html

Problem:

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

Solution:

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
}

Upvotes: 13

kaskelotti
kaskelotti

Reputation: 4823

The GitHub discussion on this topic, linked by @jarmod, also had another solution for this. I'll replicate it here for others to avoid scanning through the whole thread.

Add the following to your ~/.aws/config along with any other settings present.

[default]
cli_follow_urlparam = false

P.S. Seems that it is also mentioned in the AWS documentation under "Loading Parameters from a File" section.

Upvotes: 5

Ram K
Ram K

Reputation: 19

Another option to make this work is to not include the https protocol in the value and just the domain name or the path. After retrieval add the protocol appropriate. some times we wanted to use https or http or even ssh. Take git url for example. Multiple protocols for accessing the resource with appropriate ports where the path is the required value

Upvotes: 1

Related Questions