1

我是 DAPR 的新手。

我已经在 AWS EKS 中安装了 DAPR。

我在节点 js 代码下方(容器化并部署到 AWS EKS),其中将调用边车容器(dapr)以与 AWS S3 交互。

const express = require('express');
const bodyParser = require('body-parser');
require('isomorphic-fetch');

const app = express();
app.use(bodyParser.json());

// These ports are injected automatically into the container.
const daprPort = process.env.DAPR_HTTP_PORT; 
const daprGRPCPort = process.env.DAPR_GRPC_PORT;

const awss3name = `awss3`;
const s3url = `http://localhost:${daprPort}/v1.0/bindings/${awss3name}`;

const port = 3000;


app.get('/ports', (_req, res) => {
    console.log("DAPR_HTTP_PORT: " + daprPort);
    console.log("DAPR_GRPC_PORT: " + daprGRPCPort);
    res.status(200).send({DAPR_HTTP_PORT: daprPort, DAPR_GRPC_PORT: daprGRPCPort })
});


app.post('/s3', (req, res) => {
    const data = req.body.data;
    
    //console.log("data:-------- " + data.operation);

    console.log("s3url:-------- " + s3url);

    fetch(s3url, {
        method: "POST",
        body: JSON.stringify(data),
        headers: {
            "Content-Type": "application/json"
        }
    }).then((response) => {
        if (!response.ok) {
            throw "Failed to connect with aws s3.";
        }

        console.log("Successfully connected to s3.");
        res.status(200).send();
    }).catch((error) => {
        console.log(error);
        res.status(500).send({message: error});
    });
});

app.listen(port, () => console.log(`Node App listening on port ${port}!`));

下面是 aws s3 的绑定(组件)yaml

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: awss3
spec:
  metadata:
  - name: bucket
    value: dapr-bucket
  - name: region
    value: us-west-2
  - name: accessKey
    value: QWERASZXC143QAZ9FPZ9
  - name: secretKey
    value: AB9aQW1Za56QqaW5lkjtxc8LKUOP/X2vLOP6pPLO
  - name: sessionToken
    value: QWEEWEWQ////RTYUIOPOJHV56789GJBJJNKKJJJK
  - name: decodeBase64
    value: false
  - name: encodeBase64
    value: false
  type: bindings.aws.s3
  version: v1

当我低于 api 时,我收到错误(无法与 aws s3 通信)

方法:POST

网址:http://localhost:3000/s3

正文:{“操作”:“删除”,“元数据”:{“键”:“my-test-file.txt”}}

我得到以下错误

{
    "message": "Failed to connect with aws s3."
}

我不确定我在这里犯了什么错误,需要帮助

4

0 回答 0