dherault / dherault/serverless-offline
SLS_ACCOUNT_ID identity override for schedule events
- Dominant language
- JavaScript
- Stars
- 5.3k
- Forks
- 811
- Avg merge
- 2d 4h
- Merged PRs (30d)
- 3
Description
## 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
```yaml
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
```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**
Contributor guide
Assessment
This issue has not been assessed yet.