aws / aws-sdk-js-v3

Modularized AWS SDK for JavaScript.
Apache License 2.0
3.14k stars 580 forks source link

util-arn-parser: Add logic for extracting resource name from various ARN formats #4243

Closed clareliguori closed 1 year ago

clareliguori commented 2 years ago

Describe the feature

util-arn-parser takes a naive approach to extracting resource names from ARNs, simply splitting the ARN on : into 6 segments. I cannot always use util-arn-parser to extract a resource name from an ARN that can be directly provided to a service API. Some ARNs include resource types, and util-arn-parser returns the "resourceName" string including the resource type name.

For example:

// ARN containing resource-type/resource-name
const {resourceName} = parse('arn:aws:dynamodb:us-east-2:123456789012:table/my-table');
// Current result: resourceName => table/my-table
// Desired result: resourceName => my-table

// ARN containing /resource-type/resource-name
const {resourceName} = parse('arn:aws:servicecatalog:us-east-2:123456789012:/applications/my-application');
// Current result: resourceName => /applications/my-application
// Desired result: resourceName => my-application

// ARN containing resource-type:resource-name
const {resourceName} = parse('arn:aws:codedeploy:us-east-2:123456789012:deploymentconfig:my-deployment-config');
// Current result: resourceName => deploymentconfig:my-deployment-config
// Desired result: resourceName => my-deployment-config

Use Case

I often find myself duplicating logic to extract the resource name from ARNs:

// Get DynamoDB table name from ARN
// Example ARN: arn:aws:dynamodb:us-east-2:123456789012:table/myDynamoDBTable
const {resourceName} = parse(tableArn);
const tableName = resourceName.split("/")[1];

// Query the table
const resp = await client.send(new DescribeTableCommand({ Table: tableName }));

Ideally I would be able to parse the resource name directly, without an additional split:

const {resourceName} = parse(tableArn);
const resp = await client.send(new DescribeTableCommand({ Table: resourceName }));

Proposed Solution

The AWS CDK contains logic that could be adapted to util-arn-parser. The caller passes the expected ARN format (an enum) for the given ARN. https://github.com/aws/aws-cdk/blob/main/packages/%40aws-cdk/core/lib/arn.ts#L6-L48

Other Information

No response

Acknowledgements

SDK version used

3.208.0

Environment details (OS name and version, etc.)

Linux

l1berty commented 1 year ago

Note there is another ARN parser that likely should be addressed as part of the proposed solution: https://github.com/aws/aws-sdk-js-v3/blob/main/packages/util-endpoints/src/lib/aws/parseArn.ts

yenfryherrerafeliz commented 1 year ago

Hi @clareliguori, thanks for opening this issue. I agree with the suggested changes. I will mark this issue to be reviewed so we can address it further. I can not guarantee this will be addressed soon since we have a huge backlog and therefore we must prioritize.

Thanks!

RanVaknin commented 1 year ago

Hi @clareliguori ,

After discussing this with the team we agreed that this is a reasonable feature request, however the team currently have no bandwidth to tackle implementing this feature. Additionally feature requests are prioritized based on community engagement, and since this FR was open without any additional engagement we have concluded that its better to close this rather then letting it languish in our queue and setting false expectations.

We appreciate your patience and hope this doesn't discourage you from opening additional bug reports / feature requests int he future.

Thanks again, Ran~

github-actions[bot] commented 1 year ago

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs and link to relevant comments in this thread.