0
votes

I have two CloudFormation stacks, one for dynamodb the other is for a lambda. The lambda works as dynamodb stream target so it needs to know the DynamoDB table stream ARN. So I exported the arn from dynamodb stack and referenced it in lambda stack.

It works well. However, it doesn't allow me to turn down dynamodb stack because there is a reference in the lambda stack. Is there a way for me to allow deleting the dynamodb stack even when there is a reference? I don't care whether the lambda works or not. There are some cases I need to turn the db table and create a new one.

Below is my severless configuration for adding dynamodb stream arn on lambda:

myHandler:
  handler: src/lambdas.myHandler
  name: myHandler
  events:
    - stream:
        type: dynamodb
        arn: 
          Fn::ImportValue: '${self:provider.dynamodbStackName}-tableStreamArn'
1

1 Answers

0
votes

Sadly not with your current architecture. You can't delete a stuck which exports are used by other stacks (from docs):

After another stack imports an output value, you can't delete the stack that is exporting the output value or modify the exported output value. All of the imports must be removed before you can delete the exporting stack or modify the output value.

If you don't want to tightly couple your stacks through export-import, you could remove the import/exports and pass the DynamoDB table ARN as an parameter to your lambda stack. This way you are not coupling the stacks, and you will be able to freely delete or update the DynamoDB stack.

You could also do it the other-way around, and pass your lambda's function name to your AWS::Lambda::EventSourceMapping as a parameter. Could be easier, as it seams that the function is more persistent then the DynanoDB table.