Skip to content

Commit 3077e04

Browse files
Fix: workaround for CF bug with long ARN on ecs
1 parent a8d156b commit 3077e04

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

ecs-cf-deploy

+12-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ VERSION="0.1.0"
44
VERBOSE=false
55
AWS_CLI=$(which aws)
66
AWS_ECS="$AWS_CLI --output json ecs"
7-
AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION:="eu-west-1"}
7+
AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION:-eu-west-1}
88
AWS_ASSUME_ROLE=true
99

1010
function usage() {
@@ -22,7 +22,7 @@ Required arguments:
2222
Optional arguments:
2323
-k | --aws-access-key AWS Access Key ID. May also be set as environment variable AWS_ACCESS_KEY_ID
2424
-s | --aws-secret-key AWS Secret Access Key. May also be set as environment variable AWS_SECRET_ACCESS_KEY
25-
-r | --region AWS Region Name. May also be set as environment variable AWS_DEFAULT_REGION or use the default `eu-west-1`
25+
-r | --region AWS Region Name. May also be set as environment variable AWS_DEFAULT_REGION or use the default eu-west-1
2626
-v | --verbose Display debugging information (basically each command)
2727
2828
Requirements:
@@ -84,6 +84,16 @@ function getServiceName() {
8484
--query 'Stacks[0].Outputs[?OutputKey==`Service`].OutputValue' \
8585
--output text --region ${AWS_DEFAULT_REGION}
8686
)
87+
if [ $ECS_SERVICE_NAME == $ECS_CLUSTER_NAME ]; then
88+
echo "Long ARN bug found: using ServiceArn output to get Service name";
89+
temp_servicename=$($AWS_CLI cloudformation describe-stacks \
90+
--stack-name ${ECS_SERVICE_STACK} \
91+
--query 'Stacks[0].Outputs[?OutputKey==`ServiceArn`].OutputValue' \
92+
--output text --region ${AWS_DEFAULT_REGION}
93+
)
94+
echo $ECS_SERVICE_NAME
95+
export ECS_SERVICE_NAME=${temp_servicename##*/}
96+
fi
8797
if [ -z $ECS_SERVICE_NAME ]; then
8898
echo "Could not find the service under the '$ECS_SERVICE_STACK' stack"
8999
exit 10

test.bats

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ if [ -z $CIRCLE_SHA1 ]; then
5252
[ $status -eq 0 ]
5353
}
5454
fi
55-
@test "test call ecs-cf-deploy without args (status=255)" {
55+
@test "test call ecs-cf-deploy without args display the usage(status=3)" {
5656
run ./ecs-cf-deploy
5757
echo $output
58-
[ $status -eq 4 ]
58+
[ $status -eq 3 ]
5959
}
6060
@test "test call ecs-cf-deploy without credentials (status=255)" {
6161
run ./ecs-cf-deploy -s example-api -c example-cluster -a 12345677 -ar assumeRole

0 commit comments

Comments
 (0)