简体   繁体   中英

How to get resource identifier from ARN string using AWS SDK?

I have two AWS arns:

arn:aws:elasticloadbalancing:us-east-1:1234567890:app/cmy-app/b473fda15a743462
arn:aws:elasticloadbalancing:us-east-1:1234567890:targetgroup/my-app/1234567890

that I need to return only the targetgroup/my-app/effe001bcbfe98af and app/cmy-app/b473fda15a743462 portion. I've been trying to find a way to retrieve that through the AWS SDK but I've not been able to find the option.

I'm wondering if there is a way to do that with ruby?

You can use the Aws::ARNParser :

str = 'arn:aws:elasticloadbalancing:us-east-1:1234567890:targetgroup/my-app/1234567890'

arn = Aws::ARNParser.parse(str)
#=> #<Aws::ARN:0x00007f9b65d4b748 ...>

arn.resource
#=> "targetgroup/my-app/1234567890"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM