-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
core: Return concrete values for physical names and ARNs if explicitly stated #21487
Comments
Even within a single stack, I ought to be able to reference, say, the |
What are you trying to do? |
This issue has not received a response in a while. If you want to keep this issue open, please leave a comment below and auto-close will be canceled. |
@rix0rrr Two days is not "a while". Please fix your GitHub action configuration to be more reasonable. With regards to your question, we have a shared account in which we have to generate resource names with a unique suffix. (We can't always use the auto-generated names that CDK would pick.) In these situations we sometimes need to later feed this chosen name into some conditional logic. Due to the current way CDK works, the only way to do this is to save the name in a separate variable, which is very annoying. It is part of a larger issue where CDK does not support CloudFormation conditions, only host language ones, which means anything not resolved at synth time is a problem. |
I understand why this is frustrating. The problem is it cannot really be solved easily. We need the reference to imply a dependency, but also be readable at synth time. We want both of the following: const bucket = new Bucket(..., { bucketName: 'deterministic' });
// At deploy time, BucketUser must be sequenced AFTER Bucket
const user = new BucketUser(..., { bucketName: bucket.bucketName });
// But right now, I also want to know the literal value
if (bucket.bucketName !== 'deterministic') {
throw new Error('But I told you what it was!');
} There is not a single value we can populate
Something that might work for you is to use one of: // Probably works for resources that have properly implemented 'physicalName' support
function physicalNameOf(resource: Resource) {
const resolvedName = Stack.of(resource).resolve(resource.physicalName);
if (resolvedName === undefined) {
throw new Error(`Should have given a physical name to ${source.node.path}`);
}
return resolvedName;
}
// Or dig into the L1 properties of each type
function physicalNameOfBucket(bucket: Bucket) {
const resolvedName = Stack.of(bucket).resolve((resource.node.defaultChild as CfnBucket).bucketName);
if (resolvedName === undefined) {
throw new Error(`Bucket needs a physical name ${source.node.path}`);
}
return resolvedName;
}
function physicalNameOfUser(bucket: User) { ... }
// etc. |
I have been toying with the idea of making const probablyResolved = stack.resolve(bucket.bucketName); // Either 'deterministic' or { Ref: 'MyBucket' }
if (typeof probablyResolved === 'string') {
// ...
} Which is also not fantastic, but at least slightly more construct-agnostic than the other mechanism. Not likely to come any time soon though. |
Describe the feature
Re-opening this issue: #4093
A solution to this could be to return physical names only if embedded in a cross-environment stack. Otherwise return the token.
Use Case
Trying to reference resources across environments. This should be possible if I name the resources at compile-time. However cdk always
tokenizes
it regardless of if a static name is provided or not.Proposed Solution
No response
Other Information
No response
Acknowledgements
CDK version used
latest
Environment details (OS name and version, etc.)
mac
The text was updated successfully, but these errors were encountered: