serverless / serverless/serverless

aws cloudwatch event must have stage by stage

Open
#8,448 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

question
Dominant language
JavaScript
Stars
46.9k
Forks
5.7k
Avg merge
10h 7m
Merged PRs (30d)
57

Description

[MY ENV]

Framework Core: 2.1.0
Plugin: 4.0.3
SDK: 2.3.2
Components: 3.1.3
OS : MAC

[My serverless.yml]

service:
  name: scheduler
frameworkVersion: "2"
custom:
  prune:
    automatic: true
    number: 5
  webpack:
    webpackConfig: ./webpack.config.js
    includeModules: true
plugins:
  - serverless-dotenv-plugin
  - serverless-prune-plugin
  - serverless-webpack
provider:
  name: aws
  runtime: nodejs12.x
  region: ap-northeast-2
  memorySize: 512
  stage: ${opt:stage, 'dev'}
functions:
  hello:
    handler: ./src/handler.hello
    events:
      - schedule:
          rate: cron(0/1 * * * ? *)
          name: ${self:provider.stage}-test-scheduler // issue! ( If a scheduler with the same name is registered, the following error occurs. - ex. name: test-scheduler )
          description: "test scheduler"

I am trying to implement lambda scheduling with a cloudwatch event trigger using serverless.

First, I created a simple handler function, hooked up a cloudwatch event to a lambda, and tested the deployment by stage.

In aws it is possible to connect one cloudwatch event to multiple lambdas.

However, it seems impossible to attach one cloudwatch event to different lambda functions using the serverless framework.

[Error]

An error occurred: HelloEventsRuleSchedule1 - test-scheduler already exists in stack [ARN].

I also checked the issues below, and it was resolved by connecting a separate cloudwatch event for each stage using serverless.yml stage variable. (https://github.com/serverless/serverless/issues/3323)

However, if you do this, the number of cloudwatch events is generated for each stage.

For example, if you connect the cloudwatch event for testing on the development server and production server to lambda, there is no problem even if the same cloudwatch event is connected.
(I don't want to divide the cloudwatch event by stage and connect it.)

Is there any way to solve this?

Currently, is it best to create and connect cloudwatch events for each stage by using the stage variable of serverless.yml?

Thank you!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the serverless.yml schedule configuration and reproduce the deployment using the reported stage values and CloudWatch event name. Read the behavior and discussion in issue #3323, then determine whether sharing one event across stages and functions is supported; done means the expected behavior is implemented or clearly documented with a tested configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, javascript, node.js
Domain
cloud
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.