serverless / event-gateway-sdk Goto Github PK
View Code? Open in Web Editor NEWEvent Gateway JavaScript SDK
License: MIT License
Event Gateway JavaScript SDK
License: MIT License
The EG appears to return a 202
status code when the subscription is set to async
and a 200
status code when the subscription is set to sync
.
The SDK currently only supports a 202
response, so it doesn't work with sync subscriptions.
I tried to implement a quick fix, but ran into some other strange behavior. When you create both an async
and sync
subscription on the same path+method within the Event Gateway, the async
subscription suddenly starts returning a 200
status code instead of a 202
.
Also ran into an issue where async events are firing twice via the SDK. Ran out of time before I could figure this out.
All of this can be discovered by playing with these tests in Event Gateway & SDK, which are currently failing due to the above:
https://github.com/serverless/event-gateway-sdk/tree/support-200
Since the Event Gateway is CloudEvents friendly, it'd be nice to have an easy way to make a CloudEvent for use with the emit()
functionality.
For example:
import {SDK, Event} from '@serverless/event-gateway-sdk';
const eventGateway = new SDK({
url: 'http://myeventgateway.io',
space: 'prod'
})
// Create your CloudEvent
let event = new Event({
eventType: 'user.created',
eventTypeVersion: "1.0",
source: 'dashboard.serverless.com'
})
// Emit your event
eventGateway.emit(event)
I get the following error when I try to invoke a function with the invoke method:
Failed to invoke function eg-test due the error: function or subscription not found
I've confirmed that both the function and the subscription exists by running the listFunctions
and listSubscriptions
methods.
SDK Method:
createCORS
Params:
{
method: 'POST',
path: '/ac360-webappdemo/',
allowedOrigins: ['*'],
allowedMethods: ['POST', 'GET', 'PUT', 'DELETE']
}
Error:
Error: Failed to create CORS configuration and couldn't parse error body.
Subscriptions are set up on a path, so events may need to be emitted on a path.
Further, a user may want to include additional headers with the emit()
request, such as an Authorization
header used for Auth.
A proposed update to the emit()
signature could be:
eventGateway.emit(<CloudEvents object>, <Options>)
The usage would look like:
eventGateway.emit({
eventID: '1',
eventType: 'user.created',
cloudEventsVersion: '0.1',
source: '/services/users',
contentType: 'application/json',
data: {
userID: 'foo'
}}, {
path: /users,
headers: {
"Authorization": "Bearer 1234"
}
})
I initially had Application appmail
. I deployed to AWS with this app
. Later I decided to create a new application sendmail
. Now when I created and deployed the app for some reason the url that was set up was against the first app appmail
.
This appears available in the hosted Event Gateway, but this is missing from the SDK.
This method is very necessary when building tooling that uses the SDK.
Hi, great project ! Is it possible to write serverless functions in python, with Event gateway plugin out of the box? And will you eventually plan to create a python sdk ? I can help.
I'm having hard time enabling CORS for my POST http endpoint. Here is my function snippet from yml
functions:
sendMessage:
handler: handler.send
events:
- eventgateway:
type: sync
eventType: http.request
path: /send/message
method: POST
cors: true
I'm using 0.6.1
version of event-gateway-sdk
. I also tried to pass back the Access-Control-Allow-Origin
from my function but for OPTIONS my function wasn't getting called. I think the gateway is handling it but not sure how to set the right header via the yml file
When you have a lot of resources, listing them to find the record you are looking for is slow.
It would be faster to have getEventType(type)
getSubscription(id)
getFunction(id)
.
I'm trying to build tooling on top of the Event Gateway, but I'm unaware of the sinks that the EG can leverage and what their configuration needs are since there is no documentation on them. The EG OpenAPI is neat, but not super convenient as you have to follow a lot of the references.
Please add they types of functions the Event Gateway can interact with and what their configuration params are to this repo w/ examples.
In headers.js
we're using process.env
to extract the Event Gateway access key -->
Using process
will cause browser usage to fail since it's undefined.
We should add a check here to determine in which environment we're working and skip the process.env
setting of the accessKey
if we're in a browser
I was setting up CORS for my POST endpoint /send/message
. Initially I tried with cors:true
but what I found was that it was not setting OPTIONS
in allowedMethods
. So on suggestion by @alexdebrie I used the below configuration:
sendMessage:
handler: handler.send
events:
- eventgateway:
type: sync
eventType: http.request
path: /send/message
method: POST
cors:
origins:
- "*"
methods:
- GET
- POST
- OPTIONS
headers:
- Content-Type
- Authorization
allowCredentials: true
Now when I hit the config
endpoint:
curl -X GET https://config.slsgateway.com/v1/spaces/padmaraj-appmail/cors -H 'Authorization: Bearer '
{
"cors": [
{
"space": "padmaraj-appmail",
"corsId": "POST%2Fpadmaraj-appmail%2Fsend%2Fmessage",
"method": "POST",
"path": "/tenant-app/send/message",
"allowedOrigins": [
"*"
],
"allowedMethods": [
"GET",
"POST",
"OPTIONS"
],
"allowedHeaders": [
"Content-Type",
"Authorization"
],
"allowCredentials": true,
"metadata": {
"service": "send-notification",
"stage": "dev"
}
}
]
}
the path for which CORS is set is for /tenant-app/send/message
while the URL that is configured on the gateway(which I was able to hit to get results) is /send/message
.
I have 2 questions:
CORS: true
to include OPTIONS
method also?Right now we follow camelCase
, however the API key config follows lower case which might introduce confusion.
I'd propose to change this from apikey
to apiKey
.
I'm sure you guys are already thinking about this, but for those of us who have chosen Golang for our serverless applications, adoption of the event gateway wont be possible until there is a Golang SDK...
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.