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

4

1 回答 1

1

听起来你会想使用Claudia API Builder

在您的情况下,类似于以下内容:

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

您还需要在 create 命令中设置 --version,例如:

claudia create --region us-east-1 --deploy-proxy-api --handler main.handler --version api
于 2017-05-30T18:02:55.513 回答