# How to update launch configurations using AWS CLI?

**URL:** <https://awshq.com/t/how-to-update-launch-configurations-using-aws-cli/5082>\
**Category:** AWS Cloud Talk\
**Created:** [February 16, 2018, 9:57pm UTC](https://awshq.com/t/how-to-update-launch-configurations-using-aws-cli/5082 "2018-02-16T21:57:56Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![thunderdungeon](https://awshq.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@thunderdungeon](https://awshq.com/u/thunderdungeon)\
**Post date:** [February 16, 2018, 9:57pm UTC](https://awshq.com/t/how-to-update-launch-configurations-using-aws-cli/5082/1 "2018-02-16T21:57:56Z")

</div>

Hi,

I’m trying to update my launch configurations by using the aws autoscaling describe-launch-configurations command, manipulating the fields with jq in bash, and then creating a new launch configuration with aws autoscaling create-launch-configurations --cli-input-json.

So far, it’s actually worked pretty well except for the userData field which needs to be decoded from base64 to utf8 but once I do so, it has the shebang on a new line and creates a mess in the JSON. Has anyone successfully used the --cli-input-json command with written userData?

Please help!

PS If anyone has a better way to update launch configurations via the CLI, let me know!

* * *

**Related discussions:**

- [On October 24, AWS will test its European Sovereign Cloud without relying on its global network](https://awshq.com/t/on-october-24-aws-will-test-its-european-sovereign-cloud-without-relying-on-its-global-network/21642)
- [Can’t increase Maximum number of vCPUs assigned to the Running On-Demand Standard (A, C, D, H, I, M, R, T, Z) instances.](https://awshq.com/t/cant-increase-maximum-number-of-vcpus-assigned-to-the-running-on-demand-standard-a-c-d-h-i-m-r-t-z-instances/21125)
- [Companies asking to use my certs](https://awshq.com/t/companies-asking-to-use-my-certs/21576)
- [Account gripes](https://awshq.com/t/account-gripes/21708)
- [New UI rolling out, feels way faster!](https://awshq.com/t/new-ui-rolling-out-feels-way-faster/21690)

---

<div class="post-metadata">

**Author:** ![spressman](https://awshq.com/letter_avatar_proxy/v4/letter/s/ba8739/32.png) [@spressman](https://awshq.com/u/spressman)\
**Post date:** [February 16, 2018, 10:54pm UTC](https://awshq.com/t/how-to-update-launch-configurations-using-aws-cli/5082/2 "2018-02-16T22:54:07Z")

</div>

That sounds so very painful… Can you import the resources into terraform and manipulate there?

---

<div class="post-metadata">

**Author:** ![ranman96734](https://awshq.com/letter_avatar_proxy/v4/letter/r/bc79bd/32.png) [@ranman96734](https://awshq.com/u/ranman96734)\
**Post date:** [February 16, 2018, 11:04pm UTC](https://awshq.com/t/how-to-update-launch-configurations-using-aws-cli/5082/3 "2018-02-16T23:04:24Z")

</div>

Do you have a sample command?

---

<div class="post-metadata">

**Author:** ![daxlreod](https://awshq.com/letter_avatar_proxy/v4/letter/d/3bc359/32.png) [@daxlreod](https://awshq.com/u/daxlreod)\
**Post date:** [February 16, 2018, 11:15pm UTC](https://awshq.com/t/how-to-update-launch-configurations-using-aws-cli/5082/4 "2018-02-16T23:15:05Z")

</div>

Most of my launch configurations are inside a cloudformation stack. When I need to update the launch config, I update the cloudformation stack and it handles the messy stuff inside.

For example, if I have a new AMI for a deployment, I update the AMI parameter on the CF stack and it creates the new LC and updates the active LC on the scaling group.

---

<div class="post-metadata">

**Author:** ![thunderdungeon](https://awshq.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@thunderdungeon](https://awshq.com/u/thunderdungeon)\
**Post date:** [February 16, 2018, 11:49pm UTC](https://awshq.com/t/how-to-update-launch-configurations-using-aws-cli/5082/5 "2018-02-16T23:49:18Z")

</div>

> [@spressman](#):
>
> That sounds so very painful… Can you import the resources into terraform and manipulate there?

I’m not currently using terraform yet 😕 looking into it though!

---

<div class="post-metadata">

**Author:** ![thunderdungeon](https://awshq.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@thunderdungeon](https://awshq.com/u/thunderdungeon)\
**Post date:** [February 16, 2018, 11:50pm UTC](https://awshq.com/t/how-to-update-launch-configurations-using-aws-cli/5082/6 "2018-02-16T23:50:28Z")

</div>

> [@daxlreod](#):
>
> Most of my launch configurations are inside a cloudformation stack. When I need to update the launch config, I update the cloudformation stack and it handles the messy stuff inside. For example, if I have a new AMI for …

Hmm that’s normally what i would do but i’m trying to automate the process a little more so that i dont have to manually update the actual cloudformation template. Plus, wouldnt that involve tearing down the stack and then standing it back up? Maybe 10-15 mins?

---

<div class="post-metadata">

**Author:** ![diskis](https://awshq.com/letter_avatar_proxy/v4/letter/d/3bc359/32.png) [@diskis](https://awshq.com/u/diskis)\
**Post date:** [February 17, 2018, 12:04am UTC](https://awshq.com/t/how-to-update-launch-configurations-using-aws-cli/5082/7 "2018-02-17T00:04:26Z")

</div>

> [@thunderdungeon](#):
>
> Hmm that’s normally what i would do but i’m trying to automate the process a little more so that i dont have to manually update the actual cloudformation template. Plus, wouldnt that involve tearing down the stack and …

> so that i dont have to manually update the actual cloudformation template

No, use parameters.

> Plus, wouldnt that involve tearing down the stack and then standing it back up? Maybe 10-15 mins?

No, it’s a stack update. Takes like 10 seconds to update a launch conf with a new AMI.

---

<div class="post-metadata">

**Author:** ![diskis](https://awshq.com/letter_avatar_proxy/v4/letter/d/3bc359/32.png) [@diskis](https://awshq.com/u/diskis)\
**Post date:** [February 17, 2018, 12:07am UTC](https://awshq.com/t/how-to-update-launch-configurations-using-aws-cli/5082/8 "2018-02-17T00:07:47Z")

</div>

If you manipulate the json in the shell, you can do further manipulations there.

sed ‘/^\s\*$/d’

strips all empty lines lines from the file. You may need to adjust a bit depending on the actual json.

---

<div class="post-metadata">

**Author:** ![thunderdungeon](https://awshq.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@thunderdungeon](https://awshq.com/u/thunderdungeon)\
**Post date:** [February 17, 2018, 12:08am UTC](https://awshq.com/t/how-to-update-launch-configurations-using-aws-cli/5082/9 "2018-02-17T00:08:40Z")

</div>

> [@diskis](#):
>
> If you manipulate the json in the shell, you can do further manipulations there. sed ‘/^\s\*$/d’ strips all empty lines lines from the file. You may need to adjust a bit depending on the actual json.

Thats what i figured but doesnt the shebang have to be on it’s own line for a bash script?

---

<div class="post-metadata">

**Author:** ![thunderdungeon](https://awshq.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@thunderdungeon](https://awshq.com/u/thunderdungeon)\
**Post date:** [February 17, 2018, 12:09am UTC](https://awshq.com/t/how-to-update-launch-configurations-using-aws-cli/5082/10 "2018-02-17T00:09:11Z")

</div>

> [@diskis](#):
>
> No, use parameters. No, it’s a stack update. Takes like 10 seconds to update a launch conf with a new AMI.

I’ll try it! Thanks 🙂

---

<div class="post-metadata">

**Author:** ![diskis](https://awshq.com/letter_avatar_proxy/v4/letter/d/3bc359/32.png) [@diskis](https://awshq.com/u/diskis)\
**Post date:** [February 17, 2018, 12:16am UTC](https://awshq.com/t/how-to-update-launch-configurations-using-aws-cli/5082/11 "2018-02-17T00:16:17Z")

</div>

> [@thunderdungeon](#):
>
> Thats what i figured but doesnt the shebang have to be on it’s own line for a bash script?

Not sure what you mean, but

“UserData”: “#!/bin/bash  
echo hello!”,  
“Nextparameter”: “…”

would place the hashbang on a separate line in the script that is actually executed on the instance.

---

<div class="post-metadata">

**Author:** ![thunderdungeon](https://awshq.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@thunderdungeon](https://awshq.com/u/thunderdungeon)\
**Post date:** [February 17, 2018, 3:20am UTC](https://awshq.com/t/how-to-update-launch-configurations-using-aws-cli/5082/12 "2018-02-17T03:20:19Z")

</div>

> [@diskis](#):
>
> Not sure what you mean, but “UserData”: “#!/bin/bash echo hello!”, “Nextparameter”: “…” would place the hashbang on a separate line in the script that is actually executed on the instance.

Is this true?? I was under the impression that you can’t have new lines in a json string for some reason. I’ll try it! Thank you!

---

<div class="post-metadata">

**Author:** ![apitillidie](https://awshq.com/letter_avatar_proxy/v4/letter/a/5f9b8f/32.png) [@apitillidie](https://awshq.com/u/apitillidie)\
**Post date:** [February 17, 2018, 4:12am UTC](https://awshq.com/t/how-to-update-launch-configurations-using-aws-cli/5082/13 "2018-02-17T04:12:53Z")

</div>

Can you change the user data to download/clone a script from a repo and run that? Then you can easily iterate that script and keep the user data script static.

---

<div class="post-metadata">

**Author:** ![Skaperen](https://awshq.com/letter_avatar_proxy/v4/letter/s/b3f665/32.png) [@Skaperen](https://awshq.com/u/Skaperen)\
**Post date:** [February 17, 2018, 4:57am UTC](https://awshq.com/t/how-to-update-launch-configurations-using-aws-cli/5082/14 "2018-02-17T04:57:32Z")

</div>

i use python for launch configurations … though i generate them as needed.

python can parse the json to data structures you can easily manipulate then generate json, again, from new data.

---

<div class="post-metadata">

**Author:** ![tastycidr](https://awshq.com/letter_avatar_proxy/v4/letter/t/74df32/32.png) [@tastycidr](https://awshq.com/u/tastycidr)\
**Post date:** [February 17, 2018, 5:56am UTC](https://awshq.com/t/how-to-update-launch-configurations-using-aws-cli/5082/15 "2018-02-17T05:56:30Z")

</div>

> [@thunderdungeon](#):
>
> I’m not currently using terraform yet 😕 looking into it though!

You’re very much doing this the hard way currently. Terraform/CloudFormation are the correct answers

---

<div class="post-metadata">

**Author:** ![thunderdungeon](https://awshq.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@thunderdungeon](https://awshq.com/u/thunderdungeon)\
**Post date:** [February 17, 2018, 6:09am UTC](https://awshq.com/t/how-to-update-launch-configurations-using-aws-cli/5082/16 "2018-02-17T06:09:08Z")

</div>

> [@apitillidie](#):
>
> Can you change the user data to download/clone a script from a repo and run that? Then you can easily iterate that script and keep the user data script static.

That’s actually what the current user data does. The problem is that it looks like this

#!/bin/bash  
/usr/bin/curl [https://github.com/](https://github.com/)…

I’m trying to run it through jq so basically

```
echo ${launchConfiguration} | jq -r --arg user_data \
${user_data}' .UserData = $user_data'

```

and the launchConfiguration might look something like these [examples](https://docs.aws.amazon.com/cli/latest/reference/autoscaling/describe-launch-configurations.html)

The problem is coming from jq with the below error

jq: error: syntax error, unexpected ‘/’, expecting $end (Unix shell  
quoting issues?) at , line 1:  
/usr/bin/curl  
jq: 1 compile error

---

<div class="post-metadata">

**Author:** ![thunderdungeon](https://awshq.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@thunderdungeon](https://awshq.com/u/thunderdungeon)\
**Post date:** [February 17, 2018, 6:10am UTC](https://awshq.com/t/how-to-update-launch-configurations-using-aws-cli/5082/17 "2018-02-17T06:10:48Z")

</div>

> [@ranman96734](#):
>
> Do you have a sample command?

So below is the user data script that I’d be trying to load in

```
#!/bin/bash
/usr/bin/curl https://github.com/...

```

I’m trying to run it through jq so basically

```
echo ${launchConfiguration} | jq -r --arg user_data \
${user_data}' .UserData = $user_data'

```

and the launchConfiguration might look something like these [examples](https://docs.aws.amazon.com/cli/latest/reference/autoscaling/describe-launch-configurations.html)

The problem is coming from jq with the below error

jq: error: syntax error, unexpected ‘/’, expecting $end (Unix shell  
quoting issues?) at , line 1:

---

<div class="post-metadata">

**Author:** ![wroteit](https://awshq.com/letter_avatar_proxy/v4/letter/w/dbc845/32.png) [@wroteit](https://awshq.com/u/wroteit)\
**Post date:** [February 17, 2018, 2:29pm UTC](https://awshq.com/t/how-to-update-launch-configurations-using-aws-cli/5082/18 "2018-02-17T14:29:41Z")

</div>

user-data can be string value or file path value starting with “file://”. i’d suggest decoding redix format straight to file buffer and pass that buffer file as user-data instead of this decode-then-re-encode base64 to plain text back into base64 nonsense.

---

<div class="post-metadata">

**Author:** ![thunderdungeon](https://awshq.com/letter_avatar_proxy/v4/letter/t/71e660/32.png) [@thunderdungeon](https://awshq.com/u/thunderdungeon)\
**Post date:** [February 17, 2018, 2:31pm UTC](https://awshq.com/t/how-to-update-launch-configurations-using-aws-cli/5082/19 "2018-02-17T14:31:52Z")

</div>

> [@wroteit](#):
>
> user-data can be string value or file path value starting with “file://”. i’d suggest decoding redix format straight to file buffer and pass that buffer file as user-data instead of this decode-then-re-encode base64 to …

I wasn’t sure if you can pass the file path in when using the --cli-input-flag. I thought everything had to be “raw” json data? There’s not much docs about it 😕

---

<div class="post-metadata">

**Author:** ![wroteit](https://awshq.com/letter_avatar_proxy/v4/letter/w/dbc845/32.png) [@wroteit](https://awshq.com/u/wroteit)\
**Post date:** [February 17, 2018, 3:57pm UTC](https://awshq.com/t/how-to-update-launch-configurations-using-aws-cli/5082/20 "2018-02-17T15:57:42Z")

</div>

> [@thunderdungeon](#):
>
> I wasn’t sure if you can pass the file path in when using the --cli-input-flag. I thought everything had to be “raw” json data? There’s not much docs about it 😕

you just have to make sure userData is missing in cli-input-json data. cli-input-json doesn’t generally clobber other command arguments, but i would be lying if that’s the case for all (emr is notriously known for being the black sheep of awscli).

[Next page](https://awshq.com/t/how-to-update-launch-configurations-using-aws-cli/5082.md?page=2)
