Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

events.EventBridgeEvent is returning an empty payload when called by the EventBridge Scheduler #563

Open
ryanparsa opened this issue May 17, 2024 · 2 comments

Comments

@ryanparsa
Copy link

Hi guys,

I'm trying to invoke a Lambda function using EventBridge Scheduler, but I'm not receiving the JSON payload in the Lambda.

Here are the details:

Scheduler:

{
    "ActionAfterCompletion": "NONE",
    "Arn": "arn:aws:scheduler:us-east-1:?:schedule/default/backup1",
    "CreationDate": "2024-05-16T19:44:38.262000-07:00",
    "Description": "",
    "FlexibleTimeWindow": {
        "Mode": "OFF"
    },
    "GroupName": "default",
    "LastModificationDate": "2024-05-16T20:07:32.388000-07:00",
    "Name": "backup1",
    "ScheduleExpression": "cron(* * ? * * 2024)",
    "ScheduleExpressionTimezone": "America/?",
    "State": "ENABLED",
    "Target": {
        "Arn": "arn:aws:lambda:us-east-1:?:function:backup",
        "Input": "{\"backupID\": \"123\", \"key2\": \"value2\", \"key3\": \"value3\"}",
        "RetryPolicy": {
            "MaximumEventAgeInSeconds": 86400,
            "MaximumRetryAttempts": 0
        },
        "RoleArn": "arn:aws:iam::?:role/service-role/Amazon_EventBridge_Scheduler_LAMBDA"
    }
}

lambda:

package main

import (
	"context"
	"encoding/json"
	"fmt"
	"github.com/aws/aws-lambda-go/events"
	"github.com/aws/aws-lambda-go/lambda"
	"github.com/aws/aws-sdk-go-v2/aws"
	"github.com/aws/aws-sdk-go-v2/config"
	"log"
)



func LambdaHandler(ctx context.Context, event events.EventBridgeEvent) (*string, error) {
	fmt.Println("LambdaHandler")
	fmt.Printf("ctx: %#v\n", ctx)
	fmt.Printf("event: %#v\n", event)

	message := fmt.Sprintf("Hello %s!", "lambda")
	return &message, nil
}

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

cloud watch:


2024/05/17 04:17:20 im LambdaHandler
ctx: context.Background.WithDeadline(2024-05-17 04:17:23.103 +0000 UTC [2.999198593s]).WithValue(type *lambdacontext.key, val <not Stringer>).WithValue(type string, val Root=1-6646da50-1;Parent=1;Sampled=0;Lineage=a8ed5ba3:0)

event: {Version: ID: DetailType: Source: AccountID: Time:0001-01-01 00:00:00 +0000 UTC Region: Resources:[] Detail:[]}



go.mod

module backup

go 1.22.0

require (
	github.com/aws/aws-lambda-go v1.47.0 // indirect
	github.com/aws/aws-sdk-go-v2 v1.27.0 // indirect
	github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.6.2 // indirect
	github.com/aws/aws-sdk-go-v2/config v1.27.15 // indirect
	github.com/aws/aws-sdk-go-v2/credentials v1.17.15 // indirect
	github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.16.3 // indirect
	github.com/aws/aws-sdk-go-v2/internal/configsources v1.3.7 // indirect
	github.com/aws/aws-sdk-go-v2/internal/endpoints/v2 v2.6.7 // indirect
	github.com/aws/aws-sdk-go-v2/internal/ini v1.8.0 // indirect
	github.com/aws/aws-sdk-go-v2/internal/v4a v1.3.7 // indirect
	github.com/aws/aws-sdk-go-v2/service/internal/accept-encoding v1.11.2 // indirect
	github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.3.9 // indirect
	github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.11.9 // indirect
	github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.17.7 // indirect
	github.com/aws/aws-sdk-go-v2/service/s3 v1.54.2 // indirect
	github.com/aws/aws-sdk-go-v2/service/sso v1.20.8 // indirect
	github.com/aws/aws-sdk-go-v2/service/ssooidc v1.24.2 // indirect
	github.com/aws/aws-sdk-go-v2/service/sts v1.28.9 // indirect
	github.com/aws/smithy-go v1.20.2 // indirect
)

It appears that the events.EventBridgeEvent object in the Lambda function is empty. Any ideas on what might be causing this or how to fix it?

Thanks!

@perriea
Copy link

perriea commented Jun 6, 2024

Same problem..
@ryanparsa have you found it where the problem is ?

@skynet2
Copy link

skynet2 commented Feb 15, 2025

Ok, it looks like I found out how it works.
When you specify Input for your cloudwatch schedule

Image
Instead of receiving events.CloudWatchEvent, you will receive RAW input.

Image

Image
Instead of events.CloudWatchEvent, you need to use a struct to which you can parse your custom input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants