dherault / serverless-offline

Emulate AWS λ and API Gateway locally when developing your Serverless project
MIT License
5.16k stars 794 forks source link

SLS_ACCOUNT_ID identity override for schedule events #1739

Open Jengah opened 9 months ago

Jengah commented 9 months ago

Feature Request

SLS_ACCOUNT_ID and related env var overrides only work for http event types and not schedule events. The AccountID is an identifier that would be useful for testing cross-account Cloudwatch events triggered by rate or cron schedules.

This logic appears to live at src/events/schedule/ScheduleEvent.js, but my feeble attempts to get this working myself have thus far failed. I though it would be as simple as adding a check for the variable and importing env (see sample below), but so far have come up empty-handed, with the auto-generated id still being used.

Sample Code

service: my-service

plugins:
  - serverless-offline

provider:
  runtime: go1.x
  stage: local

functions:
  hello:
   environment:
     SLS_ACCOUNT_ID: "XXXXXXXXXXXXXXXXXXXX"
   events:
      -  schedule: rate(1 minute)
   handler: bin/hello
import { createUniqueId } from '../../utils/index.js'
import { env } from 'node:process'

export default class ScheduleEvent {
  account = env.SLS_ACCOUNT_ID || createUniqueId()

  ['detail-type'] = 'Scheduled Event'

  id =  createUniqueId()

  region = null
}

Expected behavior/code

The presence of env.SLS_ACCOUNT_ID should be used as account rather than createUniqueId()

Additional context/Screenshots