Giter Site home page Giter Site logo

aws-lambda's People

Contributors

dependabot[bot] avatar evert avatar greenkeeper[bot] avatar moeriki avatar universalhandle avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

aws-lambda's Issues

Compatibility break with core 0.19.x

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:

  • short term: change the peer deps to be >0.16 <0.19
  • longer term: identify the breaking change in core 0.19.0 and patch it

Obviously 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.

handler return type inferred as 'any'

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.

aws-lambda should catch exceptions with 'httpCode' information, and correctly emit http errors (if no error middleware is used).

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!

An in-range update of @types/node is breaking the build 🚨

The devDependency @types/node was updated from 12.7.0 to 12.7.1.

🚨 View failing branch.

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.

Status Details

FAQ and help

There is a collection of frequently asked questions. If those don’t help, you can always ask the humans behind Greenkeeper.


Your Greenkeeper Bot 🌴

AWS Context not exposed

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:

  • add AWS context under ctx.request.awsContext, or other suggestions?
  • expose types AwsRequest and AwsResponse

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.