diff --git a/cron/lambda.go b/cron/lambda.go index ea2fb6fd3ca09ffa74bc989b6f7b2d37e4b136a8..6378b5502638ee9a4c2188e76c17fba006abd369 100644 --- a/cron/lambda.go +++ b/cron/lambda.go @@ -3,6 +3,7 @@ package cron import ( "context" "math/rand" + "os" "time" "github.com/aws/aws-lambda-go/lambdacontext" @@ -16,9 +17,17 @@ func (cron Cron) Handler(lambdaCtx context.Context) (err error) { lc, _ := lambdacontext.FromContext(lambdaCtx) requestID := lc.AwsRequestID - cronName, cronFunc := cron.router.Route(lc.InvokedFunctionArn) + //if env CRON_MESSAGE_TYPE is defined, this instance only process that type + //if not, try to use ARN from the event context which allows one instance to + //call any handler + routeKey := os.Getenv("CRON_MESSAGE_TYPE") + if routeKey == "" { + routeKey = lc.InvokedFunctionArn + } + + cronName, cronFunc := cron.router.Route(routeKey) if cronFunc == nil { - return errors.Errorf("request-id:%s unknown cron function(%s)", requestID, lc.InvokedFunctionArn) + return errors.Errorf("request-id:%s unknown cron function(%s)", requestID, routeKey) } //got a handler, prepare to run: