How to support more than one trigger in AWS Lambda in Golang

0 votes

I am building an AWS Lambda function in Golang that copy the content from n to m S3 buckets. There is a requirement to support for S3 trigger as well as fetching the data from an SQS where all source S3 bucket change is stored. The code can be found here: https://github.com/maknahar/s3copy

I tried following:

func main() {
    lambda.Start(ProcessIncomingS3Events)
    lambda.Start(ProcessIncomingEvents)
}

func ProcessIncomingS3Events(event events.S3Event) error {
    ...
    log.Println("Got S3 Event")
    return processS3Trigger(config, event)
}

func ProcessIncomingEvents() error {
    ...
    log.Println("Defaulting to SQS")
    return processSQSMessage(config)
}

In this case, the first event ProcessIncomingS3Events is triggered every time.

I tried following as well

func main() {
    lambda.Start(ProcessIncomingEvents)
}

func ProcessIncomingEvents(event interface{}) error {
    ...
    switch request := event.(type) {
    case events.S3Event:
        log.Println("Got S3 Event")
        return processS3Trigger(config, request)

    case types.Nil:
        log.Println("Defaulting to SQS")
        return processSQSMessage(config)

    default:
        log.Println("Could not find the event type")

    }

    return nil
}

In this case, Lambda could not detect the type and Could not find the event type is logged in every trigger.

Is there a way to support multiple triggers via AWS SDK at all for the function?

Sep 12, 2018 in AWS by bug_seeker
• 15,510 points
3,945 views

1 answer to this question.

0 votes

In approach one, you are directly calling ProcessIncomingS3Events in first statement, so every time this is called.

Read this - Lambda Function Handler (Go)

In above link, the author is parsing event's name field. Similarly, you can check for any field which is always present in S3 event e.g. "eventSource":"aws:s3" (S3 event structure see here)

If present then S3 event else other. Or you can also check for SQS event's field.

answered Sep 12, 2018 by Priyaj
• 58,020 points

Related Questions In AWS

0 votes
1 answer

How to set-up DynamoDB trigger using AWS Lambda?

Well this code worked for me. You ...READ MORE

answered Aug 20, 2018 in AWS by Archana
• 4,170 points
2,839 views
0 votes
2 answers

How to kill a lambda function in AWS?

$ aws lambda put-function-concurrency --function-name my-function --reserved-concurrent-executions ...READ MORE

answered Mar 28, 2019 in AWS by Shashank
• 1,370 points
23,457 views
0 votes
2 answers
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
+1 vote
1 answer
0 votes
1 answer

how to access AWS S3 from Lambda in VPC

With boto3, the S3 urls are virtual by default, ...READ MORE

answered Sep 28, 2018 in AWS by Priyaj
• 58,020 points
10,121 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP