aws-backup: Unable to consume AwsCustomResource as parameter for BackupVault
Describe the bug
I am attempting to consume a custom_resources.AwsCustomResource output as the encryption_key for a new aws_backup.BackupVault.
In summary, the AwsCustomResource takes a KMS key alias and returns the original KMS key ARN.
When referencing the AwsCustomResource with method get_response_field_reference, CDK appears to ignore the parameter and has no encryption configuration for the resource in in cdk.out.
Expected Behavior
When I am referencing the AwsCustomResource within aws_backup.BackupVault, it should be able to use the returned value.
Current Behavior
The parameter encryption_key is ignored completely.
Reproduction Steps
(truncated, but should hopefully provide enough detail!)
# Custom resource to lookup the actual KMS key ARN from the Alias
KmsKeyArn = custom_resources.AwsCustomResource(
self,
f"KmsKeyIdLookup",
resource_type="Custom::KmsKeyIdLookup",
on_create=custom_resources.AwsSdkCall(
physical_resource_id=custom_resources.PhysicalResourceId.from_response(
"KeyMetadata.Arn",
),
parameters={"KeyId": KmsKeyLookup.key_id},
service="KMS",
action="describeKey",
),
policy=custom_resources.AwsCustomResourcePolicy.from_sdk_calls(
resources=["*"],
),
)
# Creating a backup vault
vault = backup.BackupVault(
self,
f"{params['VaultName']}",
backup_vault_name=params["VaultName"],
encryption_key=KmsKeyArn.get_response_field_reference("KeyMetadata.Arn"), # Referencing AwsCustomResource - this does not work and it is ignored
access_policy=vault_access_policy,
)
Possible Solution
I have overridden encryption_key_arn with the following:
cfn_vault = typing.cast(backup.CfnBackupVault, vault.node.default_child)
cfn_vault.encryption_key_arn = KmsKeyArn.get_response_field_reference("KeyMetadata.Arn").to_string()
Additional Information/Context
No response
CDK CLI Version
2.8.0 (build 8a5eb49)
Framework Version
No response
Node.js Version
v16.14.2
OS
Ubuntu 20.04 on WSL
Language
Python
Language Version
Python 3.8.10
Other information
No response
Since aws_backup.BackupVault.encryption_key takes in an IKey, I suggest trying something like this:
encryption_key=kms.Key.from_key_arn(self, 'encryption_key', KmsKeyArn.get_response_field_reference("KeyMetadata.Arn").to_string())
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.