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

SLS_ACCOUNT_ID identity override for schedule events #1739

Open
Jengah opened this issue Oct 2, 2023 · 0 comments
Open

SLS_ACCOUNT_ID identity override for schedule events #1739

Jengah opened this issue Oct 2, 2023 · 0 comments

Comments

@Jengah
Copy link

Jengah commented Oct 2, 2023

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

  • file: serverless.yml
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
  • file: src/events/schedule/ScheduleEvent.js
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

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

1 participant