Hi. I am trying to make a SQS/lambda that I can se...
# getting-started
Hi. I am trying to make a SQS/lambda that I can see the logs for. I asked the AI a few different ways (example: https://www.pulumi.com/ai/conversations/364cb211-0b96-457b-8037-6b2e48ab771d) but it keeps outputting broken code, and I am really not sure how to put this all together.
For a very simple example, I made this.
to test I call this, with
pulumi logs -f
running in another terminal, and eventually see some logs.
I think maybe part of my problem is I want them to batch, but I feel like I am getting closer with this simple example.
Hi David, I was able to get the following working:
Copy code
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
import * as awsx from "@pulumi/awsx";

// Create an AWS resource (SQS Queue)
let sqsQueue = new aws.sqs.Queue("myqueue", {
    messageRetentionSeconds: 1209600, // maximum retention period.
    visibilityTimeoutSeconds: 180     // visibility timeout of 180 seconds.

// Define the Lambda function
let lambdaFunc = new aws.lambda.CallbackFunction("myCallback", {
    callback: async (event) => {
        // Simply log the event.
        console.log("Received event: ", JSON.stringify(event));
    // Additional properties such as role, memory size, etc., can be set here if needed

// Create an event source mapping between the SQS queue and the Lambda function
const eventSourceMapping = new aws.lambda.EventSourceMapping("myEventSourceMapping", {
    eventSourceArn: sqsQueue.arn,
    functionName: lambdaFunc.name,

// Create a LogGroup for our SQS Queue and Lambda Function
const lambdaLogGroup = new aws.cloudwatch.LogGroup("lambdaLogGroup", {
    name: pulumi.interpolate`/aws/lambda/${lambdaFunc.name}`

const sqsLogGroup = new aws.cloudwatch.LogGroup("sqsLogGroup", {
    name: pulumi.interpolate`sqs/${sqsQueue.name}`

// To make our resources easily accessible, we will export their properties
export const queueURL = sqsQueue.id;
export const lambdaFunctionName = lambdaFunc.name;
export const lambdaLogGroupName = lambdaLogGroup.name;
export const sqsLogGroupName = sqsLogGroup.name;
Hope this helps!
@fierce-night-38522 Thanks! As the question sat here, I tried more things, and I came to similar code (my code above actually logs the lambda messages ok, without the extra sqs log, but I see what you are doing there. That is helpful.) I think it's starting to make a bit more sense how it all fits together.
I think maybe part of my problem originally was that I was not waiting long enough for the lambda logs and I had this whole Kafkaesque system with esbuild for my lambdas, so I could import things, etc. I am realizing there is a much simpler path that the AI seems to not mention much, of just putting the lambda code inline, and it seems to do a lot of that for me, which is great.