Skip to content

SendMessage

Source: src/AWS/SQS/SendMessage.ts

Runtime binding for sqs:SendMessage.

Bind this operation to a Queue inside a function runtime to get a callable that automatically injects the QueueUrl. The binding grants the host function sqs:SendMessage on the queue. Provide the SendMessageHttp layer on the Function to implement the binding.

Send a Message from a Lambda Function

export class ApiFunction extends Lambda.Function<Lambda.Function>()(
"ApiFunction",
) {}
export default ApiFunction.make(
{ main: import.meta.url, url: true },
Effect.gen(function* () {
const queue = yield* SQS.Queue("Jobs");
// init: bind the operation to the queue (grants sqs:SendMessage)
const sendMessage = yield* SQS.SendMessage(queue);
return {
fetch: Effect.gen(function* () {
// runtime: QueueUrl is injected automatically
const result = yield* sendMessage({ MessageBody: "hello" });
return yield* HttpServerResponse.json({
messageId: result.MessageId,
});
}).pipe(Effect.orDie),
};
}).pipe(Effect.provide(SQS.SendMessageHttp)),
);

Delay Delivery

yield* sendMessage({ MessageBody: "process later", DelaySeconds: 60 });