how can you test a reference type value in a dk stack?

I have found several options to test property references. I have not seen any documented best practice on this topic. Perhaps this is because, in most cases, we need not test such implementation details.

Option 1: Export the source Construct from its Stack. Resolve its Token value.

template.hasResourceProperties('AWS::SSM::Parameter', {
  Value: stack.resolve(stack.queue.queueName),

Option 2: As above, but use escape hatches instead of field export to get the queue reference.

const childQueue = stack.node.tryFindChild('MyQueue') as sqs.Queue;

template.hasResourceProperties('AWS::SSM::Parameter', {
  Value: stack.resolve(childQueue.queueName),

Option 3: Find the queue resource’s name in the template.

const queues = template.findResources('AWS::SQS::Queue');
const resolvedQueueName = Object.keys(queues)[0];

template.hasResourceProperties('AWS::SSM::Parameter', {
  Value: { 'Fn::GetAtt': [resolvedQueueName, 'QueueName'],},

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top