如何使用 aws

编程入门 行业动态 更新时间:2024-10-05 07:19:50

<a href=https://www.elefans.com/category/jswz/34/1771452.html style=如何使用 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

本文发布于:2024-05-30 07:55:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1770273.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何使用   aws

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!