Skip to content

(core): ExportValue does not automatically detect attribute name #12918

@McDoit

Description

@McDoit

Not possible to add ExportValue without specified name, even if the specific error says it should work this way

Reproduction Steps

Have two stacks, one with a backup bucket that i used the name from in another stack.
Removed the usage and added the ExportValue to avoid getting the cross stack error

this.ExportValue(destinationStack.BackupBucket.BucketName);

Reproduceable steps using the original BucketStack directly:

public class BucketStack : Stack
    {
        public readonly Alias BackupKeyAlias;
        //public readonly string BackupBucketArn;
        public readonly Bucket BackupBucket;
        public BucketStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props)
        {
            var keyAlias = StackName + "-backup-key";
            var backupKey = new Key(this, "backup-key", new KeyProps
            {
                TrustAccountIdentities = true,
                Description = "Key that is used for encrypting backups",
                RemovalPolicy = RemovalPolicy.DESTROY
            });

            var backupKeyAlias = backupKey.AddAlias(keyAlias);

            BackupKeyAlias = backupKeyAlias;

            var backupBucket = new Bucket(this, this.StackName + "-backups", new BucketProps
            {
                Encryption = BucketEncryption.KMS,
                EncryptionKey = backupKeyAlias,
                BlockPublicAccess = BlockPublicAccess.BLOCK_ALL,
                BucketName = StackName.ToLower() + "-backups",
                Versioned = true,
                BucketKeyEnabled = true,
                AutoDeleteObjects = true,
                RemovalPolicy = RemovalPolicy.DESTROY
            });

            BackupBucket = backupBucket;

            this.ExportValue(backupBucket.BucketName);
        }
    }

What did you expect to happen?

To create a ExportValue without having to add a name

What actually happened?

Unhandled exception. Amazon.JSII.Runtime.JsiiException: exportValue: either supply 'name' or make sure to export a resource attribute (like 'bucket.bucketName')

Environment

  • CDK CLI Version : 1.88
  • Framework Version: 1.88
  • Node.js Version: v14.13.1
  • OS : Windows 10
  • Language (Version): C# (3.1)

Other

Workaround is the add a name to the ExportValueOptions


This is 🐛 Bug Report

Metadata

Metadata

Assignees

Labels

@aws-cdk/coreRelated to core CDK functionalitybugThis issue is a bug.effort/mediumMedium work item – several days of effortneeds-triageThis issue or PR still needs to be triaged.p1

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions