-
Hello, I'm creating several cross-env buckets via the aws cdk. Everything is fine when I use my own bucket names, but if I try to use cdk.PhysicalName.GENERATE_IF_NEEDED, it throws an exception that the account is unresolved or missing. When I try to print out the account number I get the sub: ${Token[AWS.AccountId.3]}. I'm not sure why the account number wouldn't resolve if the only thing I do differently is set my own bucket names vs. allowing cloudformation to pick. Thanks in advance! const bucket = new s3.Bucket(this, "Bucket", {
bucketName: cdk.PhysicalName.GENERATE_IF_NEEDED,
encryption: s3.BucketEncryption.S3_MANAGED,
blockPublicAccess: s3.BlockPublicAccess.BLOCK_ALL,
removalPolicy: cdk.RemovalPolicy.DESTROY,
autoDeleteObjects: true
});
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I was able to solve this problem by adding my AWS Account ID as an environment variable, and then adding it as a stack prop.
|
Beta Was this translation helpful? Give feedback.
-
@iiljazi , for deplyment across environment, export function generatePhysicalName(resource: IResource): string {
const stack = Stack.of(resource);
const stackPart = new PrefixNamePart(stack.stackName, 25);
const idPart = new SuffixNamePart(Names.nodeUniqueId(resource.node), 24);
const region: string = stack.region;
if (Token.isUnresolved(region) || !region) {
throw new Error(`Cannot generate a physical name for ${Node.of(resource).path}, because the region is un-resolved or missing`);
}
const account: string = stack.account;
if (Token.isUnresolved(account) || !account) {
throw new Error(`Cannot generate a physical name for ${Node.of(resource).path}, because the account is un-resolved or missing`);
} so as @Frank3354 mentioned, solution to avoid above error would be to mention environment details. |
Beta Was this translation helpful? Give feedback.
@iiljazi , for deplyment across environment,
GENERATE_IF_NEEDED
inherently invokes this method and checks if the account details are provided-aws-cdk/packages/aws-cdk-lib/core/lib/private/physical-name-generator.ts
Line 10 in 2122461