Skip to content

Commit c2082a7

Browse files
authored
fix(backup): BackupVault.fromBackupVaultArn parses wrong arn format (#25259)
`BackupVault.fromBackupVaultArn` parsed ARNs using the `ArnFormat.SLASH_RESOURCE_NAME` format. This fix changes it to the [expected](https://docs.aws.amazon.com/service-authorization/latest/reference/list_awsbackup.html#awsbackup-resources-for-iam-policies) `ArnFormat.COLON_RESOURCE_NAME` format. Closes #25212 . ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent f628a1b commit c2082a7

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

packages/aws-cdk-lib/aws-backup/lib/vault.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,11 @@ export class BackupVault extends BackupVaultBase {
243243
* Import an existing backup vault by arn
244244
*/
245245
public static fromBackupVaultArn(scope: Construct, id: string, backupVaultArn: string): IBackupVault {
246-
const parsedArn = Stack.of(scope).splitArn(backupVaultArn, ArnFormat.SLASH_RESOURCE_NAME);
246+
const parsedArn = Stack.of(scope).splitArn(backupVaultArn, ArnFormat.COLON_RESOURCE_NAME);
247247

248+
if (parsedArn.arnFormat !== ArnFormat.COLON_RESOURCE_NAME) {
249+
throw new Error(`Backup Vault Arn ${backupVaultArn} has the wrong format, expected ${ArnFormat.COLON_RESOURCE_NAME}.`);
250+
}
248251
if (!parsedArn.resourceName) {
249252
throw new Error(`Backup Vault Arn ${backupVaultArn} does not have a resource name.`);
250253
}

packages/aws-cdk-lib/aws-backup/test/vault.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,18 @@ test('import from arn', () => {
276276
expect(vault.backupVaultArn).toEqual(vaultArn);
277277
});
278278

279+
test('import from arn should throw if arn format is incorrect', () => {
280+
// WHEN
281+
const vaultArn = stack.formatArn({
282+
service: 'backup',
283+
resource: 'backup-vault',
284+
resourceName: 'myVaultName',
285+
arnFormat: ArnFormat.SLASH_RESOURCE_NAME,
286+
});
287+
288+
expect(() => BackupVault.fromBackupVaultArn(stack, 'Vault', vaultArn)).toThrow(/has the wrong format, expected arn:aws:service:region:account:resource:resourceName/);
289+
});
290+
279291
test('import from name', () => {
280292
// WHEN
281293
const vaultName = 'myVaultName';

0 commit comments

Comments
 (0)