J'ai l'ARN d'un aval de ressources d'un compte AWS. Mon code d'infrastructure est dans AWS CDK. Dans mon code, je veux extraire les accountId à partir de l'ARN. Comment dois-je faire?
0
Il peut être réalisé avec élégance à l'aide de la base de cdk de la bibliothèque. Voici la solution:
import { Arn } from 'monocdk';
import arn = require("monocdk/lib/core/lib/arn");
private static getAccountIdFromArn(arn: string): string {
const arnComponents = Arn.parse(arn)
if(undefined === arnComponents.account) {
throw new Error(`account id not present in the arn @{arn}!`)
}
return arnComponents.account
}
Accepter la réponse si cela résout votre problème.
gshpychka