Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take integration into account when using serve command #54

Closed
jch254 opened this issue Nov 2, 2016 · 5 comments
Closed

Take integration into account when using serve command #54

jch254 opened this issue Nov 2, 2016 · 5 comments

Comments

@jch254
Copy link

jch254 commented Nov 2, 2016

Hey thanks for the great work with this!

Serverless have made Lambda Proxy Integration the default - see https://serverless.com/framework/docs/providers/aws/events/apigateway. This means that the full content of the HTTP request (headers, body, etc.) is passed to the Lambda function and the full response (headers, status code, body) must be returned from the Lambda function.

As far as I can see serverless webpack serve does not take this into account. This causes a mismatch between what the event object contains when running locally and when running on AWS. I'm using serverless-webpack in a project which uses the lambda-proxy integration and have worked around this by utilising NODE_ENV (e.g. https://github.com/jch254/serverless-es6-dynamodb-webapi/blob/master/src/handler.js#L125).

It'd be great to support both integrations.

@jch254
Copy link
Author

jch254 commented Nov 2, 2016

Below is the result of JSON.stringify(event) when runnning on AWS:

{
    "resource": "/items/{id}",
    "path": "/items/5e050b4d-bf1c-5b05-8234-decc4db60d5a",
    "httpMethod": "PATCH",
    "headers": {
        "Accept": "*/*",
        "Accept-Encoding": "gzip, deflate, sdch, br",
        "Accept-Language": "en-US,en;q=0.8",
        "Cache-Control": "no-cache",
        "CloudFront-Forwarded-Proto": "https",
        "CloudFront-Is-Desktop-Viewer": "true",
        "CloudFront-Is-Mobile-Viewer": "false",
        "CloudFront-Is-SmartTV-Viewer": "false",
        "CloudFront-Is-Tablet-Viewer": "false",
        "CloudFront-Viewer-Country": "AU",
        "Content-Type": "application/json",
        "Host": "34yerz3mq3.execute-api.ap-southeast-2.amazonaws.com",
        "Origin": "chrome-extension://fhbjgbiflinjbdggehcddcbncdddomop",
        "Postman-Token": "a493627a-a614-1e78-ad99-bca7f6bb7f6a",
        "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",
        "Via": "1.1 3f8fa9ba9aa3deb5686547631abdbb15.cloudfront.net (CloudFront)",
        "X-Amz-Cf-Id": "B10XVZLYnaTshKrTrbVeT2ILKXDgLmeLm71b3zsHtbx0L_ks-TsBjQ==",
        "X-Forwarded-For": "49.3.114.80, 54.240.152.117",
        "X-Forwarded-Port": "443",
        "X-Forwarded-Proto": "https"
    },
    "queryStringParameters": null,
    "pathParameters": {
        "id": "5e050b4d-bf1c-5b05-8234-decc4db60d5a"
    },
    "stageVariables": null,
    "requestContext": {
        "accountId": "*",
        "resourceId": "c4sedy",
        "stage": "prod",
        "requestId": "7fc983de-a0e0-11e6-a9e1-61df3d60ce53",
        "identity": {
            "cognitoIdentityPoolId": null,
            "accountId": null,
            "cognitoIdentityId": null,
            "caller": null,
            "apiKey": null,
            "sourceIp": "49.3.114.80",
            "accessKey": null,
            "cognitoAuthenticationType": null,
            "cognitoAuthenticationProvider": null,
            "userArn": null,
            "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/54.0.2840.71 Safari/537.36",
            "user": null
        },
        "resourcePath": "/items/{id}",
        "httpMethod": "PATCH",
        "apiId": "34yerz3mq3"
    },
    "body": "{\n\t\"name\": \"Wes Snipes\"\n}"
}

@thenikso
Copy link
Contributor

thats great news! is there any chance you could open a PR on this? It would take a while for me to get up to speed on the matter.

Anyhow this will probably be addressed in a v1.1 of this plugin.

@jch254
Copy link
Author

jch254 commented Nov 18, 2016

For sure, I should have some time over the next week to give it a crack. Sounds good!

@dangler
Copy link

dangler commented Dec 2, 2016

#53 This PR seems to be a start.

@HyperBrain
Copy link
Member

serve will be removed in the next v3.0.0 release in favor of serverless-offline (see #152 ). No efforts will be spent on the function anymore. So I'll close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants