Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parsing secrets from AWS secrets manager using AWS cli

I am retrieving secrets I have stored in AWS secrets manager with the AWS cli like this:

aws secretsmanager get-secret-value --secret-id secrets 

Which returns

arn:aws:secretsmanager<ID>:secret:my_secrets <number> my_secrets {"API_KEY":"ABCDEFGHI"}       <UUID string> VERSIONSTAGES   AWSCURRENT 

Does anyone know how I only get the secret ("API_KEY": "ABCDEFGHI")? I need to move these secrets to my register-task-definition environment variables. The best way would be to store them in a file and delete it after us or store them in variable. It is running on a linux machine.

like image 680
Moddaman Avatar asked Jun 18 '18 14:06

Moddaman


People also ask

How do you get secrets from secret Manager?

You can retrieve your secrets by using the console (https://console.aws.amazon.com/secretsmanager/ ) or the AWS CLI ( get-secret-value ). In applications, you can retrieve your secrets by calling GetSecretValue in any of the AWS SDKs. However, we recommend that you cache your secret values by using client-side caching.

How do I connect to AWS Secret Manager?

Open the Amazon VPC console, select Endpoints, and then select Create Endpoint. Select AWS Services as the Service category, and then, in the Service Name list, select the Secrets Manager endpoint service named com. amazonaws.

Can Lambda Access secrets Manager?

Your lambda function will be able to execute all Secrets Manager actions on the secret.


Video Answer


2 Answers

Use the --query option of the CLI to extract just the secret.

aws secretsmanager get-secret-value --secret-id secrets --query SecretString --output text 
like image 186
helloV Avatar answered Sep 18 '22 23:09

helloV


aws secretsmanager get-secret-value --secret-id secrets| jq --raw-output '.SecretString' | jq -r .API_KEY

using jq you can print.

like image 33
Vijay Kumar Avatar answered Sep 17 '22 23:09

Vijay Kumar