Skip to content

Commit 4b954e4

Browse files
committed
[sdlf-utils] better handling of aws profile argument in legislators example
1 parent 22b7d74 commit 4b954e4

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

sdlf-cicd/deploy-cicd.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ aws cloudformation deploy \
182182
${REGION:+--region "$REGION"} \
183183
${PROFILE:+--profile "$PROFILE"} || exit 1
184184

185-
if ! "$dflag"
185+
if "$dflag"
186186
then
187187
CODEBUILD_ROLE=$(aws codebuild batch-get-projects --names "sdlf-cicd-$1" --query "projects[0].serviceRole" --output text ${REGION:+--region "$REGION"} ${PROFILE:+--profile "$PROFILE"} | cut -d'/' -f2)
188188
CODEBUILD_ROLE_BOOTSTRAP=$(aws codebuild batch-get-projects --names "sdlf-cicd-bootstrap" --query "projects[0].serviceRole" --output text ${REGION:+--region "$REGION"} ${PROFILE:+--profile "$PROFILE"} | cut -d'/' -f2)

sdlf-utils/workshop-examples/legislators/deploy.sh

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,44 +19,43 @@ do
1919
esac
2020
done
2121

22-
if ! "$pflag"
22+
if "$pflag"
2323
then
24-
echo "-p not specified, using default..." >&2
25-
PROFILE="default"
24+
echo "using AWS profile $PROFILE..." >&2
2625
fi
27-
REGION=$(aws configure get region --profile "$PROFILE")
26+
REGION=$(aws configure get region ${PROFILE:+--profile "$PROFILE"})
2827

29-
ARTIFACTS_BUCKET=$(aws --region "$REGION" --profile "$PROFILE" ssm get-parameter --name "/sdlf/storage/rArtifactsBucket/dev" --query "Parameter.Value" --output text)
30-
aws s3 cp "$DIRNAME/scripts/legislators-glue-job.py" "s3://$ARTIFACTS_BUCKET/artifacts/" --profile "$PROFILE"
28+
ARTIFACTS_BUCKET=$(aws --region "$REGION" ssm get-parameter --name "/sdlf/storage/rArtifactsBucket/dev" --query "Parameter.Value" --output text ${PROFILE:+--profile "$PROFILE"})
29+
aws s3 cp "$DIRNAME/scripts/legislators-glue-job.py" "s3://$ARTIFACTS_BUCKET/artifacts/" ${PROFILE:+--profile "$PROFILE"}
3130

3231
mkdir "$DIRNAME"/output
3332

3433
function send_legislators()
3534
{
3635
ORIGIN="$DIRNAME/data/"
3736

38-
RAW_BUCKET=$(aws --region "$REGION" --profile "$PROFILE" ssm get-parameter --name "/sdlf/storage/rRawBucket/dev" --query "Parameter.Value" --output text)
39-
KMS_KEY=$(aws --region "$REGION" --profile "$PROFILE" ssm get-parameter --name "/sdlf/dataset/rKMSDataKey/dev" --query "Parameter.Value" --output text)
37+
RAW_BUCKET=$(aws --region "$REGION" ssm get-parameter --name "/sdlf/storage/rRawBucket/dev" --query "Parameter.Value" --output text ${PROFILE:+--profile "$PROFILE"})
38+
KMS_KEY=$(aws --region "$REGION" ssm get-parameter --name "/sdlf/dataset/rKMSDataKey/dev" --query "Parameter.Value" --output text ${PROFILE:+--profile "$PROFILE"})
4039

4140
S3_DESTINATION=s3://$RAW_BUCKET/
4241
COUNT=0
4342
for FILE in "$ORIGIN"/*.json;
4443
do
4544
(( COUNT++ )) || true
46-
aws s3 cp "$FILE" "${S3_DESTINATION}legislators/" --profile "$PROFILE" --sse aws:kms --sse-kms-key-id "$KMS_KEY"
45+
aws s3 cp "$FILE" "${S3_DESTINATION}legislators/" --sse aws:kms --sse-kms-key-id "$KMS_KEY" ${PROFILE:+--profile "$PROFILE"}
4746
echo "transferred $COUNT files"
4847
done
4948
}
5049

51-
VPC_SUPPORT=$(aws --region "$REGION" --profile "$PROFILE" ssm get-parameter --name "/SDLF/VPC/Enabled" --query "Parameter.Value" --output text 2>/dev/null)
50+
VPC_SUPPORT=$(aws --region "$REGION" ssm get-parameter --name "/SDLF/VPC/Enabled" --query "Parameter.Value" --output text ${PROFILE:+--profile "$PROFILE"} 2>/dev/null)
5251
if [ -z "$VPC_SUPPORT" ]
5352
then
54-
aws --region "$REGION" --profile "$PROFILE" ssm put-parameter --name "/SDLF/VPC/Enabled" --value "false" --type String
53+
aws --region "$REGION" ssm put-parameter --name "/SDLF/VPC/Enabled" --value "false" --type String ${PROFILE:+--profile "$PROFILE"}
5554
fi
5655

5756
aws cloudformation package --template-file "$DIRNAME"/scripts/legislators-glue-job.yaml \
5857
--s3-bucket "$ARTIFACTS_BUCKET" \
59-
--profile "$PROFILE" \
58+
${PROFILE:+--profile "$PROFILE"} \
6059
--output-template-file "$DIRNAME"/output/packaged-template.yaml
6160

6261
STACK_NAME="sdlf-legislators-glue-job"
@@ -67,6 +66,6 @@ aws cloudformation deploy \
6766
--tags Framework=sdlf \
6867
--capabilities "CAPABILITY_NAMED_IAM" "CAPABILITY_AUTO_EXPAND" \
6968
--region "$REGION" \
70-
--profile "$PROFILE" || exit 1
69+
${PROFILE:+--profile "$PROFILE"} || exit 1
7170

7271
send_legislators

0 commit comments

Comments
 (0)