curveball / aws-lambda Goto Github PK
View Code? Open in Web Editor NEWRun curveball applications on AWS Lambda
License: MIT License
Run curveball applications on AWS Lambda
License: MIT License
aws-lambda
v0.2.2 doesn't work with core
v0.19.0.
This simple application:
import { Application } from '@curveball/core';
import problemMiddleware from '@curveball/problem';
import lambdaHandler from '@curveball/aws-lambda';
const app = new Application();
// order of middlewares matters; "problem" should be at or near the top for error handling
app.use(problemMiddleware());
app.use((ctx) => {
ctx.response.body = 'Hello, cruel world!';
});
export const handler = lambdaHandler(app);
... compiles but yields runtime errors:
✖ Unhandled exception in handler 'webhook'.
✖ Cannot convert undefined or null to object
✖ TypeError: Cannot convert undefined or null to object
at Function.keys (<anonymous>)
at new Headers (/home/universalhandle/Code/sample-project/node_modules/@curveball/core/dist/headers.js:7:34)
at new MemoryRequest (/home/universalhandle/Code/sample-project/node_modules/@curveball/core/dist/memory-request.js:14:28)
at /home/universalhandle/Code/sample-project/node_modules/@curveball/aws-lambda/dist/index.js:9:25
at InProcessRunner.run (file:///home/universalhandle/Code/sample-project/node_modules/serverless-offline/src/lambda/handler-runner/in-process-runner/InProcessRunner.js:87:20)
at async MessagePort.<anonymous> (file:///home/universalhandle/Code/sample-project/node_modules/serverless-offline/src/lambda/handler-runner/worker-thread-runner/workerThreadHelper.js:25:14)
aws-lambda
states a peer dependency on core
versions >=0.16 <1
. Potential fixes:
>0.16 <0.19
core
0.19.0 and patch itObviously the second fix is the "right" fix, but I haven't investigated it yet; it took quite a bit of debugging to get just this far. I figured there was a chance you'd know right away what the problem is, so I decided to open this before digging any deeper.
This might be a regression from one of the two minor releases this week. I'm pretty sure this was working before I upgraded. See update in follow-up comment.
Today I noticed my linter complaining about:
const app: Application
Unsafe assignment of an any value.eslint(@typescript-eslint/no-unsafe-assignment)
...for code like:
import handler from '@curveball/aws-lambda';
// ...
export const router = handler(app);
I believe this is due at least in part to node_modules/@curveball/aws-lambda/dist/index.d.ts
exporting an interface directly from @types/aws-lambda
. The file contents are:
import { Application } from '@curveball/core';
import { APIGatewayProxyHandler } from 'aws-lambda';
export default function lambdaHandler(app: Application): APIGatewayProxyHandler;
My IDE shows an error for aws-lambda on line 2: Cannot find module 'aws-lambda' or its corresponding type declarations.
Per the manual, a package that exports another package's types should declare the latter as a dependency in package.json rather than devDependency.
I'm not sure if I'm failing to build the dist correctly or what, but making this change alone does not seem to correct the problem.
Hello.
I saw curveball/core#92, but I must be missing something. I've got code like this:
// handler.ts
import { Application, invokeMiddlewares } from '@curveball/core';
import handler from '@curveball/aws-lambda';
import { fooRoutes } from './components/foo/routes';
const app = new Application();
app.use(ctx => invokeMiddlewares(ctx, fooRoutes));
export const router = handler(app);
// components/foo/routes.ts
import router from '@curveball/router';
import { fooController } from './controller'; // just has a "get" method
export const fooRoutes = [
router('/:id/foo', fooController),
];
The relevant bit of serverless.yml looks like so:
functions:
my-function:
handler: src/handler.router
events:
- http:
# sends everything through to the router
path: /{proxy+}
method: any
When I visit localhost:3000/12345/foo
, I get the expected result.
When I visit any other path (note: I've defined none), I get a 200 and an empty page. I would expect a 404 or a 405. Is handling of nonexistent routes not automagic? Did I miss a step?
If it's not handled automatically, is there a recommend best practice? (I didn't try too long, but a wildcard route didn't seem to do the trick either.)
Thanks!
12.7.0
to 12.7.1
.This version is covered by your current version range and after updating it in your project the build failed.
@types/node is a devDependency of this project. It might not break your production code or affect downstream projects, but probably breaks your build or test tools, which may prevent deploying or publishing.
There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.
Your Greenkeeper Bot 🌴
The default AWS handler has two arguments: event
, and context
.
It seems like context is not used in curveball, which is fine. But it would be convenient to have it available on the ctx.request
.
Right now if I want to access the AWS context I have to do this before forwarding the event to Curveball.
export function handle(event: any, context: Context): Promise<any> {
context.callbackWaitsForEmptyEventLoop = false;
return handler(app)(event);
}
Additionally there are internal types for AwsRequest
and AwsResponse
that are not exposed. I had to type them as any
in the code above.
Would you accept PR to:
ctx.request.awsContext
, or other suggestions?AwsRequest
and AwsResponse
I'm confused. Can you please tell me if Curveball supports Vercel somehow?
https://vercel.com/docs/runtimes#advanced-usage/advanced-node-js-usage/aws-lambda-api
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.