1

I'm running into what I'm sure is a simple issue I'm overlooking. I'm trying to change an AWS EC2 InstanceType using the CLI via a Powershell Script. Everything is running fine up until I go to actually modify the InstanceType.

I've tried multiple different variations and combinations of escape characters to get this to work, but I can't so far.

Invoke-Expression 'aws ec2 modify-instance-attribute --instance-id $thisID --instance-type \"{`\"Value`\":`\"m4.large`\"}"'

What I'm trying to achieve is the equivalent to this:

aws ec2 modify-instance-attribute --instance-id i-1234567890abcdef0 --instance-type "{\"Value\": \"m1.small\"}"
3
  • 1
    Running commands external to PowerShell can introduce some issues. Curly braces have special meaning in PowerShell. You will need to escape them in a PowerShell terminal such as: '{"Value": "m4.large"}'. The single quote makes it a string literal. Commented Aug 6, 2019 at 22:01
  • 2
    As an aside: Don't use Invoke-Expression (or any other cmdlet) to synchronously invoke console applications: invoke them directly. Specifically, Invoke-Expression should generally be avoided Commented Aug 7, 2019 at 2:01
  • 1
    @mklement0 Yes, good point on that. Great reference from 2011, but still relevant today! Never ever use Invoke-Expression outside of PowerShell unless you know exactly what the implications are. Commented Aug 7, 2019 at 20:33

1 Answer 1

3

You can use the AWS Tools for Powershell and use the following command:

Edit-EC2InstanceAttribute -InstanceId $thisID --InstanceType m4.large

Documentation Reference: https://docs.aws.amazon.com/powershell/latest/reference/Index.html

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for the assist @Peter Kay
You're welcome anytime @JasonWH... good luck with everything!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.