azngunit81
azngunit81

Reputation: 1604

bash command substituation comes up blank

I have the following Dockerfile

FROM public.ecr.aws/docker/library/python:3.7-slim-buster as base
WORKDIR /code
RUN apt-get update -y && \
    pip install --upgrade pip && \
    mkdir ~/.aws \
    && touch ~/.aws/credentials
RUN apt-get install -y nodejs npm awscli jq

Which is base from slim-buster. I am trying to do a one command aws stscommand from this recommended AWS sts assume role in one command solution

However the the eval solution is coming up "blank" or the parenthesis is not escaped properly within a make command:

sts-qa:
    eval $(aws sts assume-role --role-arn arn:aws:iam::1234556778:role/aws-role --role-session-name pebble | jq -r '.Credentials | "export AWS_ACCESS_KEY_ID=\(.AccessKeyId)\n export AWS_SECRET_ACCESS_KEY=\(.SecretAccessKey)\nexport AWS_SESSION_TOKEN=\(.SessionToken)\n"')

the error I get is:

root@b79fd0ebf8cf:/code# make sts-qa
eval \n export AWS_SECRET_ACCESS_KEY=\(.SecretAccessKey)\n export AWS_SESSION_TOKEN=\(.SessionToken)\n"')
/bin/sh: 1: Syntax error: ")" unexpected

I have tried:

I have ran out of ideas

Upvotes: 0

Views: 146

Answers (1)

chepner
chepner

Reputation: 530833

$(...) is Makefile syntax for expanding a variable name, so the ( is closed by the first unescaped ) in the command you want to execute. You need to double the $ to have it be treated literally.

sts-qa:
        eval $$(aws sts assume-role --role-arn arn:aws:iam::1234556778:role/aws-role --role-session-name pebble | jq -r '.Credentials | "export AWS_ACCESS_KEY_ID=\(.AccessKeyId)\n export AWS_SECRET_ACCESS_KEY=\(.SecretAccessKey)\nexport AWS_SESSION_TOKEN=\(.SessionToken)\n"')

Upvotes: 2

Related Questions