Winston
Winston

Reputation: 1428

AWS SAM lambda destination

I am a newbie to AWS Serverless Architecture. I would like to use lambda to do something and then send the result to SQS. I would like to do that using SAM - hopefully it would build the resource (SQS, Lambda function) without doing it manually. The code is very similar to this.

I would like to define all the resource in the .yml. After running the sam deploy command it created the SQS and Lambda function. After the SQS is created I would update the Lambda code so it would send data using the right SQS URL. However I would like to see if I could automate the whole process (without filling the URL of the newly created SQS).

  1. It's possible that the sam deploy command would create the Queue the first time and then it would feed the URL directly to lambda.
  2. When I went to AWS lambda console, I could see the deployed lambda function. However I couldn't see that the SQS is defined as the destination of the lambda function.

Thanks in advance.

Upvotes: 0

Views: 358

Answers (1)

fedonev
fedonev

Reputation: 25669

You can wire everything up in one go.

Is it possible that the sam deploy command would create the Queue the first time and then it would feed the URL directly to lambda?

Yes. SAM/CloudFormation uses Intrinsic Functions in your templates to assign values to properties that are not available until runtime. The AWS::SQS::Queue resource exposes several such properties. In the referenced template, for instance, QueuePublisherFunction receives the queue URL as an environment variable:

Environment:
  Variables:
    SQSqueueName: !Ref MySqsQueue # When you pass the logical ID of this resource to the intrinsic Ref function, Ref returns the queue URL.

When I went to AWS lambda console, I could see the deployed lambda function. However I couldn't see that the SQS is defined as the destination of the lambda function.

That's expected. If you are following the template, your Lambdas were not configured with a Destination, which has special meaning in Lambda-speak (e.g. optionally used in error handling).

Where can you view how the Queue is wired to your Lambda? Your Queue should be visible in the QueueConsumerFunction Lambda console as a "trigger". Your QueueConsumerFunction should be visible in the SQS console as a "Lambda trigger". Your QueuePublisherFunction is not coupled with the queue at the infrastructure level. It just puts messages in the queue.

Upvotes: 1

Related Questions