Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Dynamic triggers for was lambda functions

NotificationsYou must be signed in to change notification settings

failsafe-engineering/serverless-aws-lambda-dynamic-trigger

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The plugin can register triggers (events) for a lambda function dynamically at the time of the deployment.The usual static trigger (event) definitions can be completely omitted.The original idea is to make the same lambda function triggered by different events on different environments (stages).This way we can even do some basicfeature switching.

How it works

The plugin when the host code gets deployed...

  1. Fetches the value of a defined parameter from the Parameter Store. The value must be a list ARNs separated by commas. (If there is only one trigger it's just a single ARN)
  2. Parses the individual ARNs and pulls out the name of the aws service.
  3. Registers the ARNs as triggers with the configured lambda function or functions.

Please note that you can only use the plugin withsns,sqs orkinesis triggers.

Like ondev foo lambda function is triggered by

  • arn:aws:sns:eu-west-2:123456654321:topic1
  • arn:aws:sns:eu-west-2:123456654321:topic2
  • arn:aws:sns:eu-west-2:123456654321:topic3

While onprod foo lambda function is triggered by

  • arn:aws:sns:eu-west-2:123456654321:topic1
  • arn:aws:sns:eu-west-2:123456654321:topic2

This way we can switch features on and off on different stages.

The dynamic trigger sets need to be stored in the Parameter Store of the Systems Manager (SSM) and it should look somewhat like this:

  • Name: /dev/dynamic-trigger
  • Value: arn:aws:sns:eu-west-2:123456654321:topic1,arn:aws:sns:eu-west-2:123456654321:topic2,arn:aws:sns:eu-west-2:123456654321:topic3

or

  • Name: /prod/dynamic-trigger
  • Value: arn:aws:sns:eu-west-2:123456654321:topic1,arn:aws:sns:eu-west-2:123456654321:topic2

The config parameters:

  • region: {string} the region of the Systems Manager -> Parameter Store
  • functions: {Array<name: string, ssmPath: string>}
    • name: {string} The name of the function
    • ssmPath: {string} It's actually the name of the parameter in the Parameter Store

Example

The configuration in the serverless.yml:

plugins:- @kakkuk/serverless-aws-lambda-dynamic-triggercustom:dynamicTrigger:region:"eu-west-2"// !!! Optional !!! It'll fall back to AWS_DEFAULT_REGION if it's not setfunctions:      -name:"handler1"ssmPath:"/${opt:stage}/trigger-set1"// This is the dynamic part :)      -name:"handler2"ssmPath:"/${opt:stage}/trigger-set2"// This is the dynamic part :)// Further down in the serverless.ymlhandler1:handler:src/handler1name:${self:service}-handler1// No events section neededhandler2:handler:src/handler1name:${self:service}-handler2// No events section needed

About

Dynamic triggers for was lambda functions

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp