1

I am new to AWS Lambda.

As given in the documentation, I deployed the following sample on AWS Lambda using Claudia:

'use strict';
console.log('Loading hello world function');

exports.handler = function (event, context, callback) {
    var name = "World";
    var responseCode = 200;
    console.log("request: " + JSON.stringify(event));
    if (event.queryStringParameters !== null && event.queryStringParameters !== undefined) {
        if (event.queryStringParameters.name !== undefined && event.queryStringParameters.name !== null && event.queryStringParameters.name !== "") {
            console.log("Received name: " + event.queryStringParameters.name);
            name = event.queryStringParameters.name;
        }

        if (event.queryStringParameters.httpStatus !== undefined && event.queryStringParameters.httpStatus !== null && event.queryStringParameters.httpStatus !== "") {
            console.log("Received http status: " + event.queryStringParameters.httpStatus);
            responseCode = event.queryStringParameters.httpStatus;
        }
    }

    var responseBody = {
        message: "Hello " + name + "!",
        input: event
    };
    var response = {
        statusCode: responseCode,
        headers: {
            "x-custom-header": "my custom header value"
        },
        body: JSON.stringify(responseBody)
    };
    console.log("response: " + JSON.stringify(response))
    callback(null, response);
};

The command I used to deploy using Claudia is:

claudia create --region us-east-1 --deploy-proxy-api --handler main.handler

It created a URL that looks like: https://40barfooxpyj.execute-api.us-east-1.amazonaws.com/latest

Why do I get the string latest in the URL? How could I make the URL look like: https://40barfooxpyj.execute-api.us-east-1.amazonaws.com/api/jobs

Suhail Gupta
  • 22,386
  • 64
  • 200
  • 328

1 Answers1

1

Sounds like you'll want to use Claudia API Builder

In your case, something along the lines of:

api.get('jobs', function(request) {
    return "Hello " + request.queryString.name + "!";
});

You'll also want to set --version in your create command, for example:

claudia create --region us-east-1 --deploy-proxy-api --handler main.handler --version api
  • 1
    --version api will change "latest" to "api", api.get('jobs', ... creates a final endpoint of /api/jobs – mernstacking May 30 '17 at 18:22
  • Okay. What If I need `api/jobs` at the end? – Suhail Gupta May 30 '17 at 18:38
  • 1
    I'm not sure what you're asking here... Following my answer, your endpoint will be: `https://40barfooxpyj.execute-api.us-east-1.amazonaws.com/api/jobs` or: `https://40barfooxpyj.execute-api.us-east-1.amazonaws.com/api/jobs?name=bob` – mernstacking May 30 '17 at 18:47
  • Okay! How should I define a proxy resource? Also, I do not want to use claudia api builder. What should be the approach then to parse the HTTP requests? – Suhail Gupta May 30 '17 at 18:52
  • 1
    [https://claudiajs.com/tutorials/deploying-proxy-api.html](https://claudiajs.com/tutorials/deploying-proxy-api.html) API builder is pretty much the standard in handling HTTP requests within claudia.. The answer to how to do that otherwise is outside of the scope of the initial question. – mernstacking May 30 '17 at 19:00