如何使用 aws"/>
如何使用 aws
Reactjs
const result = await invokeLambda(points);
调用Lambda.js
const AWS = require("aws-sdk");
export const invokeLambda = async (
points: any
) => {
console.log("manual lambda call being made");
AWS.config.update({
accessKeyId: "id",
secretAccessKey: "AccessKey",
region: "region"
})
const lambda = new AWS.Lambda();
return lambda.invoke({
FunctionName: 'my-lambda-fn',
InvocationType: 'RequestResponse',
Payload: JSON.stringify({
path: '/api/v5.1/points',
body: JSON.stringify(points)
}),
})
.promise();
}
节点/快递(AWS-lambda)
const express = require("express");
const awsServerlessExpress = require("aws-serverless-express");
const app = express();
const server = awsServerlessExpress.createServer(app)
const cors = require("cors");
...
...
const pointsRoute = require("./src/routes/points.route");
...
app.use(`./api/v5.1/points`, pointsRoute);
module.exports.handler = (event, context) => {
console.log("Event", event); // I can see this log in cloudwatch
console.log("Context", context); // I can see this log in cloudwatch
return awsServerlessExpress.proxy(server, event, context);
}
points.controller.js
exports.postPoints = (req, res, next) => { // not hitting controller
console.log("hitting postPoints controller method", req); // not logging this line
console.log("req object", req);
...
...
}
错误
{
"statusCode": 404,
"body": "{\"message\":\"Requested Endpoint doesn't not exist\"}",
"headers": {
"x-powered-by": "Express",
"access-control-allow-origin": "*",
"connection": "keep-alive",
"keep-alive": "timeout=30",
"access-control-allow-headers": "X-Requested-With,content-type",
"access-control-allow-methods": "GET, POST, OPTIONS, PUT, PATCH, DELETE",
"access-control-allow-credentials": "true",
"content-type": "application/json; charset=utf-8",
"content-length": "50",
"date": "Mon, 24 Apr 2023 15:51:49 GMT"
},
"isBase64Encoded": false
}
我不确定我做错了什么但是控制器方法没有被击中。
回答如下:更多推荐
如何使用 aws
发布评论