#bash (2021-04)

A channel for bash scripting

2021-04-13

2021-04-12

Brij S avatar
Brij S

does anyone know how to convert a list (output from awscli) into JSON with key:value?

aaratn avatar
aaratn

doesnt --output json help from aws-cli ?

mikesew avatar
mikesew

comma-separated list, or rows?

aws <cmd>
a,b,c
# or
aws s3 ls
a
b
c
Brij S avatar
Brij S

Hi all, I’m trying to dynamically obtain the ARNS of aws resource share invitations. I found that the data source for RAM doesn’t really support this. I’m attempting to mimic this example instead and I’ve been able to retrieve the ARNS using the following awscli command below:

aws ram get-resource-share-invitations \
    --query 'resourceShareInvitations[*]|[?contains(resourceShareName,`prefix`)==`true`].resourceShareInvitationArn' \
    --region us-east-1 

However, I’m not sure how I can get it into the correct format that data.external requires. Ideally Id want the output to be:

{ resrouceShareName: resourceShareInvitationArn }
Brij S avatar
Brij S

I think I’ve almost got it, with the following code

invitations=$(aws ram get-resource-share-invitations \
    --query 'resourceShareInvitations[*]|[?contains(resourceShareName,`prefix`)==`true`].[resourceShareName,resourceShareInvitationArn]' \
    --region us-east-1)

jq -c  '.[0] as $keys | .[1] as $values | reduce range(0; $keys|length) as $i  ( {}; . + { ($keys[$i]): $values[$i] })' <<< $invitations

I get the names together and the arns together, not sure whats wrong

1
    keyboard_arrow_up