Skip to content

Commit 710fe96

Browse files
authored
Merge pull request #187 from awszhen/codebuild
Add option for specifying AWS CLI Profile
2 parents d54a6cf + 0dade21 commit 710fe96

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

local_builds/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Download and use our codebuild_build.sh script to run your local builds.
2525
**Optional:**
2626
-l Used to override the default local agent image.
2727
-c Use the AWS configuration and credentials from your local host. This includes ~/.aws and any AWS_* environment variables.
28+
-p Used to specify the AWS CLI Profile.
2829
-b Used to specify a buildspec override file. Defaults to buildspec.yml in the source directory.
2930
-e Used to specify a file containing environment variables.
3031
-m Used to mount the source directory to the customer build container directly.

local_builds/codebuild_build.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ function usage {
4040
echo " * Use additional (-s) in <sourceIdentifier>:<sourceLocation> format for secondary source"
4141
echo " * For sourceIdentifier, use a value that is fewer than 128 characters and contains only alphanumeric characters and underscores"
4242
echo " -c Use the AWS configuration and credentials from your local host. This includes ~/.aws and any AWS_* environment variables."
43+
echo " -p Used to specify the AWS CLI Profile."
4344
echo " -b FILE Used to specify a buildspec override file. Defaults to buildspec.yml in the source directory."
4445
echo " -m Used to mount the source directory to the customer build container directly."
4546
echo " -e FILE Used to specify a file containing environment variables."
@@ -57,7 +58,7 @@ artifact_flag=false
5758
awsconfig_flag=false
5859
mount_src_dir_flag=false
5960

60-
while getopts "cmi:a:s:b:e:l:h" opt; do
61+
while getopts "cmi:a:s:b:e:l:p:h" opt; do
6162
case $opt in
6263
i ) image_flag=true; image_name=$OPTARG;;
6364
a ) artifact_flag=true; artifact_dir=$OPTARG;;
@@ -67,6 +68,7 @@ while getopts "cmi:a:s:b:e:l:h" opt; do
6768
s ) source_dirs+=("$OPTARG");;
6869
e ) environment_variable_file=$OPTARG;;
6970
l ) local_agent_image=$OPTARG;;
71+
p ) aws_profile=$OPTARG;;
7072
h ) usage; exit;;
7173
\? ) echo "Unknown option: -$OPTARG" >&2; exit 1;;
7274
: ) echo "Missing option argument for -$OPTARG" >&2; exit 1;;
@@ -144,6 +146,12 @@ then
144146
else
145147
docker_command+=" -e \"AWS_CONFIGURATION=NONE\""
146148
fi
149+
150+
if [ -n "$aws_profile" ]
151+
then
152+
docker_command+=" -e \"AWS_PROFILE=$aws_profile\""
153+
fi
154+
147155
docker_command+="$(env | grep ^AWS_ | while read -r line; do echo " -e \"$line\""; done )"
148156
fi
149157

0 commit comments

Comments
 (0)