# Possible to specify events for specific environment only for AWS Lambda?

**URL:** <https://forum.serverless.com/t/possible-to-specify-events-for-specific-environment-only-for-aws-lambda/10538>\
**Category:** Serverless Framework\
**Tags:** aws, lambda\
**Created:** [February 12, 2020, 2:04pm UTC](https://forum.serverless.com/t/possible-to-specify-events-for-specific-environment-only-for-aws-lambda/10538 "2020-02-12T14:04:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![QAnders](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/qanders/32/3151_2.png) [@QAnders](https://forum.serverless.com/u/QAnders)\
**Post date:** [February 12, 2020, 2:04pm UTC](https://forum.serverless.com/t/possible-to-specify-events-for-specific-environment-only-for-aws-lambda/10538/1 "2020-02-12T14:04:43Z")

</div>

```
    events:
      - schedule: cron(0 02 * * ? *) # Timezone: UTC

```

I want to set a reoccurring event but only in Production environment. Is that possible to configure int eh Serverless.yaml?

---

<div class="post-metadata">

**Author:** ![cheesiangcs](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/cheesiangcs/32/3980_2.png) [@cheesiangcs](https://forum.serverless.com/u/cheesiangcs)\
**Post date:** [February 13, 2020, 9:31am UTC](https://forum.serverless.com/t/possible-to-specify-events-for-specific-environment-only-for-aws-lambda/10538/2 "2020-02-13T09:31:09Z")

</div>

You can take a look on the [serverless-plugin-ifelse](https://www.npmjs.com/package/serverless-plugin-ifelse)

```auto
custom:
  myStage: ${opt:stage, self:provider.stage}
  serverlessIfElse:
        # Deploy schedule only in production env
        - If: '"${self:custom.myStage}" != "production"'
          Exclude:
            - functions.yourfunction.events.0.schedule

```

---

<div class="post-metadata">

**Author:** ![QAnders](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/qanders/32/3151_2.png) [@QAnders](https://forum.serverless.com/u/QAnders)\
**Post date:** [March 6, 2020, 7:56am UTC](https://forum.serverless.com/t/possible-to-specify-events-for-specific-environment-only-for-aws-lambda/10538/3 "2020-03-06T07:56:03Z")

</div>

Thanks, however managed to figure it out as:

```
custom:
  stage: "${opt:stage, self:provider.stage}"
  prod:
    schedule: cron(0 02 * * ? *) # Timezone: UTC; Only run schedule in prod
  dev:
    schedule:
  test:
    schedule:
  qa:
    schedule:

```

And then for the Function:

```
events:
  - schedule: ${self:custom.${self:custom.stage}.schedule}
```

---

<div class="post-metadata">

**Author:** ![mattcaruso](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/mattcaruso/32/5513_2.png) [@mattcaruso](https://forum.serverless.com/u/mattcaruso)\
**Post date:** [April 7, 2021, 10:22pm UTC](https://forum.serverless.com/t/possible-to-specify-events-for-specific-environment-only-for-aws-lambda/10538/4 "2021-04-07T22:22:26Z")

</div>

When I try to take this strategy, I’m getting a warning (which will soon be an error in a new version)

```
`A valid service attribute to satisfy the declaration 'self:custom.dev.myVariableName' could not be found.`

```

because I have that empty, as you showed above. How did you get around that?

---

<div class="post-metadata">

**Author:** ![CaioF](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/caiof/32/6850_2.png) [@CaioF](https://forum.serverless.com/u/CaioF)\
**Post date:** [May 18, 2022, 8:29pm UTC](https://forum.serverless.com/t/possible-to-specify-events-for-specific-environment-only-for-aws-lambda/10538/5 "2022-05-18T20:29:34Z")

</div>

I’m having the same issue as @mattcaruso, but now it fails to build/deploy with  
` - Cannot resolve variable at "functions.my-function.events.0.schedule": Value not found at "self" source`  
any idea what to do?  
My usecase: Using serverless to deploy a lambda, I have a function with a cloudWatch cron event. I don’t want to just disable for dev stage, I want to avoid creating the event at all when deploying to dev, only creating it when the function is deployed to prod
