示例代码(Node.js):
const AWS = require('aws-sdk'); const lambda = new AWS.Lambda(); const apigateway = new AWS.APIGateway();
exports.handler = async (event, context) => { console.log(event); try { const response = { statusCode: 200, body: JSON.stringify('Hello from Lambda!'), }; return response; } catch (err) { console.log(err); return err; } };
{ "swagger": "2.0", "info": {...}, "basePath": "/prod", "schemes": [ "https" ], "paths": { "/users/{userId}": { "get": { "summary": "Get user by ID", "parameters": [ { "name": "userId", "in": "path", "required": true, "type": "string" } ], "responses": { "200": {...} }, "x-amazon-apigateway-integration": { "uri": "arn:aws:apigateway:us-east-1:lambda:path/2015-03-31/functions/arn:aws:lambda:us-east-1:account-id:function:function-name/invocations", "responses": {...}, "passthroughBehavior": "when_no_templates", "httpMethod": "POST", "contentHandling": "CONVERT_TO_TEXT", "type": "aws_proxy" } } } } }
const AWS = require('aws-sdk'); const lambda = new AWS.Lambda();
exports.handler = async (event, context) => { console.log(event); try { const response = { statusCode: 200, body: JSON.stringify('Hello from Lambda!'), }; return response; } catch (err) { console.log(err); return err; } };
{ "swagger": "2.0", "info": {...}, "x-amazon-apigateway-throttle-settings": {...}, "x-amazon-apigateway-request-validators": {...}, "definitions": {...}, "basePath": "/prod", "schemes": [