rubenkaiser / serverless-offline-eventbridge Goto Github PK
View Code? Open in Web Editor NEWA serverless offline plugin that enables eventBridge events
A serverless offline plugin that enables eventBridge events
Serverless now supports (from v2.28.0 onwards) to create EventBridge resources using CloudFormation directly instead of using a custom lambda (serverless/serverless#8437).
That enables customers to use CloudFormation intrinsic functions when defining the trigger of a lambda function. For instance:
functions:
consumeEvent:
handler: events.consume
events:
- eventBridge:
eventBus: !GetAtt EventBus.Arn # Assuming EventBus is a resource already defined in the CF template
or
consumeEvent:
handler: events.consume
events:
- eventBridge:
eventBus: !ImportValue EventBusNameFromOtherStack # Assuming the EventBus is created by a different CF stack
The issue comes when we try to run serverless-offline-eventBridge, The above definitions are not supported.
I have extended this plugin to support both scenarios. Are PRs welcomed?
Do you think this supports events on stepfunctions? I have an SF triggered by an event bridge event, but for some reason, the stepfunction is never triggered.
It seems that in 7f91a14 support for scheduled events (e.g. cron
and rate
expressions) was removed.
I'm not sure this was intentional - the README still claims "Scheduled events are also supported. When a cron fires the event object that is sent along is an empty object." and scheduled events are a key part of EventBridge.
Could schedule support be reintroduced, or at the very least can the README be corrected to say that scheduled events are not supported. Thanks! ๐
If I have an eventBridge event that triggers a lambda that uses the equals-ignore-case filter, such as:
- eventBridge:
pattern:
source:
- my-awesome-source
detail:
info:
- equals-ignore-case: AwEsOmE-DatA
We get hit with the following message:
The equals-ignore-case eventBridge filter is not supported in serverless-offline-aws-eventBridge yet. Please consider submitting a PR to support it.
Adding a PR very soon.
Hello.
cron(*/1 * * * ? *)
(as same as rate(1 minute)
) is worked correctly, but cron(0/1 * * * ? *)
is not worked.
Both seem to work the same when set on the AWS console. However, the AWS documentation says cron(0/1 * * * ? *)
is correct.
Therefore, it is possible to avoid it, but I would appreciate it if you could fix it.
Thanks.
Framework Core: 3.22.0 (local)
Plugin: 6.2.2
SDK: 4.3.2
"serverless-offline": "^10.1.0",
"serverless-offline-aws-eventbridge": "^2.0.1",
https://github.com/rubenkaiser/serverless-offline-eventBridge/blob/master/src/index.js#L391 crashes when the event handler is not a javascript function.
Could we remove these lines? all calls to the handler function use an empty context.
Hi, I'm getting errors as follows:
serverless-offline-aws-eventbridge :: error: [object Object] occurred in reportAssetEventBridge on 1/10, will retry
Is the error message not expected to be an Object?
Thanks!
When serverless-offline-eventBridge
receive a too large payload, we got this error
PayloadTooLargeError: request entity too large
fi-serverless-local | at readStream (/app/node_modules/raw-body/index.js:155:17)
fi-serverless-local | at getRawBody (/app/node_modules/raw-body/index.js:108:12)
fi-serverless-local | at read (/app/node_modules/body-parser/lib/read.js:77:3)
fi-serverless-local | at jsonParser (/app/node_modules/body-parser/lib/types/json.js:135:5)
fi-serverless-local | at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
fi-serverless-local | at trim_prefix (/app/node_modules/express/lib/router/index.js:317:13)
fi-serverless-local | at /app/node_modules/express/lib/router/index.js:284:7
fi-serverless-local | at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)
fi-serverless-local | at next (/app/node_modules/express/lib/router/index.js:275:10)
fi-serverless-local | at cors (/app/node_modules/cors/lib/index.js:188:7)
fi-serverless-local | at /app/node_modules/cors/lib/index.js:224:17
fi-serverless-local | at originCallback (/app/node_modules/cors/lib/index.js:214:15)
fi-serverless-local | at /app/node_modules/cors/lib/index.js:219:13
fi-serverless-local | at optionsCallback (/app/node_modules/cors/lib/index.js:199:9)
fi-serverless-local | at corsMiddleware (/app/node_modules/cors/lib/index.js:204:7)
fi-serverless-local | at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
fi-serverless-local | at trim_prefix (/app/node_modules/express/lib/router/index.js:317:13)
fi-serverless-local | at /app/node_modules/express/lib/router/index.js:284:7
fi-serverless-local | at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)
fi-serverless-local | at next (/app/node_modules/express/lib/router/index.js:275:10)
fi-serverless-local | at expressInit (/app/node_modules/express/lib/middleware/init.js:40:5)
fi-serverless-local | at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
fi-serverless-local | at trim_prefix (/app/node_modules/express/lib/router/index.js:317:13)
fi-serverless-local | at /app/node_modules/express/lib/router/index.js:284:7
fi-serverless-local | at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)
fi-serverless-local | at next (/app/node_modules/express/lib/router/index.js:275:10)
fi-serverless-local | at query (/app/node_modules/express/lib/middleware/query.js:45:5)
fi-serverless-local | at Layer.handle [as handle_request] (/app/node_modules/express/lib/router/layer.js:95:5)
fi-serverless-local | at trim_prefix (/app/node_modules/express/lib/router/index.js:317:13)
fi-serverless-local | at /app/node_modules/express/lib/router/index.js:284:7
fi-serverless-local | at Function.process_params (/app/node_modules/express/lib/router/index.js:335:12)
fi-serverless-local | at next (/app/node_modules/express/lib/router/index.js:275:10)
fi-serverless-local | at Function.handle (/app/node_modules/express/lib/router/index.js:174:3)
fi-serverless-local | at Function.handle (/app/node_modules/express/lib/application.js:174:10)
fi-serverless-local | at Server.app (/app/node_modules/express/lib/express.js:39:9)
fi-serverless-local | at Server.emit (node:events:394:28)
fi-serverless-local | at Server.emit (node:domain:470:12)
fi-serverless-local | at parserOnIncoming (node:_http_server:924:12)
fi-serverless-local | at HTTPParser.parserOnHeadersComplete (node:_http_common:127:17)
I do debug myself I found it's likely from express.json limit size (currently "10mb") https://github.com/rubenkaiser/serverless-offline-eventBridge/blob/master/src/index.js#L131
Should we increase it or let it configurable?
I can give it a try if you are happy @rubenkaiser
If the serverless.yml uses external files for the function declaration the functions are not parsed.
Example:
functions:
- ${file(./application/routesA.yml)}
- ${file(./application/routesB.yml)}
When I add this dependency to a project and start the serverless with sls offline start
I get an error stating Cannot find module 'serverless-offline/dist/lambda'
. When I comment out serverless-offline-eventBridge
in plugins the error goes away.
Expected behaviour would be for it to run.
Versions
Framework Core: 2.40.0 (local)
Plugin: 4.5.3
SDK: 4.2.2
Components: 3.9.2
Package:
"esbuild": "^0.14.42",
"serverless": "^3.19.0",
"serverless-dynamodb-local": "^0.2.40",
"serverless-esbuild": "^1.30.0",
"serverless-offline": "^8.8.0",
"serverless-offline-aws-eventbridge": "^1.6.6",
"serverless-plugin-monorepo": "^0.10.0",
Output
Error: Cannot find module 'serverless-offline/dist/lambda'
Require stack:
- /fake/base/src/node_modules/serverless-offline-aws-eventbridge/src/index.js
- /fake/base/src/stacks/api/node_modules/serverless/lib/utils/import-module.js
- /fake/base/src/stacks/api/node_modules/serverless/lib/classes/plugin-manager.js
- /fake/base/src/stacks/api/node_modules/serverless/lib/serverless.js
- /fake/base/src/stacks/api/node_modules/serverless/scripts/serverless.js
- /fake/base/src/stacks/api/node_modules/serverless/bin/serverless.js
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/fake/base/src/node_modules/serverless-offline-aws-eventbridge/src/index.js:9:16)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at module.exports (/fake/base/src/stacks/api/node_modules/serverless/lib/utils/import-module.js:5:12)
at PluginManager.requireServicePlugin (/fake/base/src/stacks/api/node_modules/serverless/lib/classes/plugin-manager.js:171:14)
at PluginManager.resolveServicePlugins (/fake/base/src/stacks/api/node_modules/serverless/lib/classes/plugin-manager.js:198:29)
at async PluginManager.loadAllPlugins (/fake/base/src/stacks/api/node_modules/serverless/lib/classes/plugin-manager.js:136:36)
at async Serverless.init (/fake/base/src/stacks/api/node_modules/serverless/lib/serverless.js:141:5)
at async /fake/base/src/stacks/api/node_modules/serverless/scripts/serverless.js:591:7
serverless.yml
...
plugins:
- serverless-esbuild
- serverless-plugin-monorepo
- serverless-dynamodb-local
- serverless-offline
- serverless-offline-aws-eventbridge
The latest version is now v8 and npm throws an error because of invalid peer dependency (currently dependent on v6).
I've been trying on a project to disable an eventBridge with the enabled
flag for testing purposes. And it doesn't seem to work with offline. See below for an example, am I missing something?
consumeEvent:
handler: events.consume
events:
- eventBridge:
eventBus: marketing
enabled: false
pattern:
source:
- acme.newsletter.campaign
Hi there, thanks for this great plugin! I'm running into an issue with eventbridge subscriptions that use pattern matching, ie in my serverless.ts
:
'created-customer': {
handler: 'handlers/events/created.ts',
events: [
{
eventBridge: {
eventBus: '${cf:graph-event-ingest-${self:provider.stage}.EventBusArn}',
pattern: {
source: ['graph'],
'detail-type': ['insert', 'manual'],
detail: {
trigger: {
// @ts-ignore: this is a valid pattern
name: ['company'],
},
},
},
},
},
],
},
(@types/serverless
complains about the pattern, but serverless deploys it fine and is a valid event pattern -- this part is working)
When I run sls offline
and make a request, I get the following error though:
TypeError: subscriber.event.pattern.detail[key].includes is not a function
at /Users/michaelnason/Code/flavortown/node_modules/serverless-offline-aws-eventbridge/src/index.js:199:50
Thats brings me to this check:
serverless-offline-eventBridge/src/index.js
Lines 198 to 200 in da736dc
Where key
is 'trigger'
and subscriber.event.pattern.detail[key]
is { name: [ 'company' ] }
Removing the detail
part of the pattern gets us around this error, but we use this type of matching pretty heavily in our subscriptions, and would love to be able to test offline more thoroughly. Do you have any suggestions?
I can't get serverless-offline-eventBridge to work with the latest version of serverless-offline.
When I start my dev server I get the following error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist/lambda' is not defined by "exports" in /Users/me/my-api/node_modules/serverless-offline/package.json
When I remove the package, everything bundles fine and my app runs. I think it may be failing due to the latest node import changes.
Hope to get some help ๐
node v16.15.0
// package.json deps
"serverless-dynamodb-local": "^0.2.40",
"serverless-esbuild": "^1.32.5",
"serverless-offline": "^9.1.0",
"serverless-offline-aws-eventbridge": "^1.6.7",
// serverless.yml
plugins:
- serverless-esbuild
- serverless-dynamodb-local
- serverless-offline
- serverless-offline-aws-eventbridge
// eventbridge.yml
Effect: Allow
Action:
- events:PutEvents
Resource:
- '*'
> serverless offline start --host 0.0.0.0 --httpPort 4000
Environment: darwin, node 16.15.0, framework 3.21.0 (local), plugin 6.2.2, SDK 4.3.2
Docs: docs.serverless.com
Support: forum.serverless.com
Bugs: github.com/serverless/serverless/issues
Error:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './dist/lambda' is not defined by "exports" in /Users/me/my-api/node_modules/serverless-offline/package.json
at new NodeError (node:internal/errors:372:5)
at throwExportsNotFound (node:internal/modules/esm/resolve:472:9)
at packageExportsResolve (node:internal/modules/esm/resolve:753:3)
at resolveExports (node:internal/modules/cjs/loader:482:36)
at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at Object.<anonymous> (/Users/me/my-api/node_modules/serverless-offline-aws-eventbridge/src/index.js:9:16)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Module.require (node:internal/modules/cjs/loader:1005:19)
at require (node:internal/modules/cjs/helpers:102:18)
at module.exports (/Users/me/my-api/node_modules/serverless/lib/utils/import-module.js:5:12)
at PluginManager.requireServicePlugin (/Users/me/my-api/node_modules/serverless/lib/classes/plugin-manager.js:171:14)
at PluginManager.resolveServicePlugins (/Users/me/my-api/node_modules/serverless/lib/classes/plugin-manager.js:198:29)
at async PluginManager.loadAllPlugins (/Users/me/my-api/node_modules/serverless/lib/classes/plugin-manager.js:136:36)
at async Serverless.init (/Users/me/my-api/node_modules/serverless/lib/serverless.js:141:5)
at async /Users/me/my-api/node_modules/serverless/scripts/serverless.js:591:7
As title
If you set a pattern that involves detail
in your serverless config, this will not inspect that pattern causing misfires on event handlers.
Also doesn't handle the callback signature that is optional for event bridge callbacks.
I've added these capabilities in this fork (https://github.com/myadbox/serverless-offline-eventBridge), happy to set up a pull request if you're interested.
If you post an event to the event bridge a 200 response is returned, but the response does not contain a valid JSON structure. The response structure is defined as follows according to the AWS docs:
{
"Entries": [
{
"ErrorCode": "string",
"ErrorMessage": "string",
"EventId": "string"
}
],
"FailedEntryCount": number
}
This causes issues with the PHP SDK, because it tries to de-serialize the response, and expects a JSON object.
It seems this change 043cafb has broken the retries mechanism.
Now, whenever a lambda throws an error, the event isn't retried and serverless-offline is stopped due to an unhandled error.
Hi I've noticed that an event in EventBridge is passed in this format (as seen from cloudwatch logs):
{
source: "some source",
"detail-type": "some detail-type",
detail: { someCustomDetail : "detail"}
}
whereas the plugin passes data in this format
{
Source: "some source",
DetailType: "some detail-type",
Detail: { someCustomDetail : "detail"}
}
Is there a way to ensure these are consistent?
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/serverless-offline
npm ERR! dev serverless-offline@"^11.0.1" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer serverless-offline@"^10.0.0" from [email protected]
npm ERR! node_modules/serverless-offline-aws-eventbridge
npm ERR! dev serverless-offline-aws-eventbridge@"^2.0.1" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
Lambda is not triggered if the event payload contains an array of objects that should match an event pattern like the following:
#payload
"services": [
{
"name": "order"
}
]
#event pattern
services:
name:
- order
Testing locally with the plugin doesn't subscribe the downstream lambda function to the event, but it works fine when deployed.
I like to suggest to rename the custom key name to support serverless.ts TypeScript Files.
TypeScript:
custom: {
webpack: {
webpackConfig: './webpack.config.js',
includeModules: true
},
'serverless-offline-aws-eventbridge': {
port: 4010,
debug: true,
account: '',
convertEntry: false
},
},
Using camelCase key 'serverlessOfflineAwsEventbridge' "looks" better and the apostrophe could be deleted.
After upgrading from 1.5.2 to 1.6.0 the sls deploy freezes and times out in our deployment (seed.run).
The last two log entries are:
Serverless: Invoke aws:package:finalize
Serverless: Invoke aws:common:moveArtifactsToPackage
The serverless packages listed in package.json are:
"serverless": "2.43.1",
"serverless-dependson-plugin": "^1.1.2",
"serverless-dotenv-plugin": "3.9.0",
"serverless-dynamodb-local": "0.2.39",
"serverless-esbuild": "1.12.0",
"serverless-offline": "7.0.0",
"serverless-offline-aws-eventbridge": "1.6.0",
"serverless-offline-dynamodb-streams": "4.2.0",
"serverless-plugin-epsagon": "1.11.1",
"serverless-plugin-resource-tagging": "1.1.0",
"serverless-s3-local": "0.6.17",
"serverless-stack-output": "0.2.3",
After reverting to 1.5.2 the build no longer freezes.
Inside serverless.ts the appropriate configuration is:
provider: {
eventBridge: {
useCloudFormation: true,
},
}
...
custom: {
'serverless-offline-aws-eventbridge': {
port: 4010,
debug: true,
account: '12345678',
},
}
Hi. I just wanted to find out some specific information. I'll like to setup serverless-offline-eventBridge with python but I currently can't figure out how to do it. Looking at npm, it says as of version 1.4.0 this plugin also supports non-javascript handlers.
The JS handler in the examples/same-stack-publisher-subscriber includes this specific piece of code, which I've found to be the crucial component I can't replicate in Python.
const eventBridge = new AWS.EventBridge({
endpoint: "http://127.0.0.1:4080/",
region: "eu-west-1",
});
Mainly the endpoint. Looking at the AWS SDK documentation I can't find any information about what endpoint does, and so I'm confused. The Python docs also don't mention endpoint like the way it's done in the code above.
Apart from using endpoint, is there any way to tell event bridge how to locate same-stack-publisher-subscriber?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.