Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get AWS account ID from curl in powershell

Does anyone know how to get the AWS account id in powershell?, I would like to do the this from the curl command, and have this running well under linux from here:

https://stackoverflow.com/questions/51597492/how-to-get-aws-account-number-id-based-on-ec2-instance-which-is-hosted-in-amazo#:~:text=You%20can%20obtain%20the%20account,%2Finstance%2Didentity%2Fdocument.&text=This%20gives%20me%20%22Unable%20to,running%20%22aws%20configure%22.%22

Specifically this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

curl -s http://169.254.169.254/latest/dynamic/instance-identity/document | sed -nE 's/.*"accountId"\s*:\s*"(.*)".*/\1/p'

And I can use the curl command in windows get get the same output but without parsing like this

curl http://169.254.169.254/latest/dynamic/instance-identity/document

but I have no idea how to parse and get just the accountId number, or the instanceId if I need that..

I have tried the Select statement, but get no meaningful results.

Any help would be appreciated.

Thanks in advance..

>Solution :

You can use:

$account_id = ((curl http://169.254.169.254/latest/dynamic/instance-identity/document).Content | ConvertFrom-Json).accountId
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading