File tree Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Expand file tree Collapse file tree 2 files changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -11,13 +11,18 @@ import "regexp"
1111//
1212
1313var arnEc2InstanceRe = regexp .MustCompile (`^arn:aws:ec2:.+/([^/]+)` )
14+ var arnLoadBalancerIdRe = regexp .MustCompile (`^arn:aws:elasticloadbalancing:[^:]+:\d+:loadbalancer/(.+)$` )
1415var arnEcsTaskToClusterRe = regexp .MustCompile (`^(arn:aws:ecs:[^:]+:\d+):task/([^/]+)/.*` )
1516var arnCloudFrontDistributionRe = regexp .MustCompile (`^arn:aws:cloudfront::\d+:distribution/([^/]+)` )
1617
1718func Ec2InstanceIdFromArn (arn string ) string {
1819 return arnEc2InstanceRe .ReplaceAllString (arn , "${1}" )
1920}
2021
22+ func LoadBalancerIdFromArn (arn string ) string {
23+ return arnLoadBalancerIdRe .ReplaceAllString (arn , "${1}" )
24+ }
25+
2126func EcsTaskArnToClusterArn (arn string ) string {
2227 return arnEcsTaskToClusterRe .ReplaceAllString (arn , "${1}:cluster/${2}" )
2328}
Original file line number Diff line number Diff line change @@ -17,6 +17,18 @@ func TestEc2InstanceIdFromArnErr(t *testing.T) {
1717 assert .Equal (t , arn , result )
1818}
1919
20+ func TestLoadBalancerIdFromArn (t * testing.T ) {
21+ arn := "arn:aws:elasticloadbalancing:us-west-1:1234567890:loadbalancer/app/my-load-balancer/50dc6c495c0c9188"
22+ result := LoadBalancerIdFromArn (arn )
23+ assert .Equal (t , "app/my-load-balancer/50dc6c495c0c9188" , result )
24+ }
25+
26+ func TestLoadBalancerIdFromArnErr (t * testing.T ) {
27+ arn := "invalid-arn"
28+ result := LoadBalancerIdFromArn (arn )
29+ assert .Equal (t , arn , result )
30+ }
31+
2032func TestEcsTaskArnToClusterArn (t * testing.T ) {
2133 result := EcsTaskArnToClusterArn ("arn:aws:ecs:us-west-1:1234567890:task/my-cluster/3f8fae2a-33ce-4c19-ba06-3f3009a7c33a" )
2234 assert .Equal (t , "arn:aws:ecs:us-west-1:1234567890:cluster/my-cluster" , result )
You can’t perform that action at this time.
0 commit comments