Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Serverless Framework: CloudFormation Variable Import/Export

I'm using Serverless Framework and have multiple services which are attempting to use the same SQS queue. I can successfully make the resource in the first service but the second one is missing the lambda trigger when deployed to AWS. Hardcoding the ARN ID will successfully make the trigger so I can only assume I have something wrong with my syntax/indentation, but it's very similar to how I'm exporting/importing my API Gateway details and I'm just not seeing it.

I have an SQS Queue set up and exported from my first service like this:

resources:
  - Resources:
      InitializeAuthenticationQueue:
        Type: "AWS::SQS::Queue"
        Properties:
          QueueName: "InitializeAuthenticationQueue"
  - Outputs:
      InitializeAuthenticationQueueArnId:
        Value:
          Fn::GetAtt:
            - InitializeAuthenticationQueue
            - Arn
        Export:
          Name: ${self:provider.stage}-InitializeAuthenticationQueueQueueArnId

In my second service I am attempting to use the SQS ARN ID as a trigger for a function, like this:

functions:
  authenticationIntialize:
    handler: myHandlerFile.myHandler
    events:
      - sqs:
        arn:
          'Fn::ImportValue': ${self:provider.stage}-InitializeAuthenticationQueueArnId

I've also tried this to see if I have my indentation wrong:

functions:
  authenticationIntialize:
    handler: myHandlerFile.myHandler
    events:
      - sqs:
          arn:
            'Fn::ImportValue': ${self:provider.stage}-InitializeAuthenticationQueueArnId

Feel like I'm missing something obvious on this one, but I've been stuck on it way too long. Anyone able to help me spot the obvious?

like image 625
jProg2015 Avatar asked May 11 '26 21:05

jProg2015


1 Answers

What errors do you get? What does the generated .serverless/cloudformation-template-update-stack.json have for the export and import values?

I usually find it easier to use the internal Serverless CloudFormation property reference. So where you are trying to import the SQS ARN do this:

${cf:STACK_NAME.InitializeAuthenticationQueueArnId}

where STACK_NAME is the name of the CloudFormation stack generated by the Serverless deployment this has the SQS ARN output. Using this method the way you reference the value to import is via the CloudFormation key and not the export name (which is admittedly confusing)

like image 157
Brian Winant Avatar answered May 13 '26 19:05

Brian Winant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!