DAPR with AWS EKS, S3

Viewed 205

i'm new to DAPR.

i've installed DAPR in AWS EKS.

i've below node js code (containerised and deployed into AWS EKS) where in it will call side-car container (dapr) for interacting with 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}!`));

below is the binding (component) yaml for aws s3

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

when i hit below api, i get error (not able to communicate with aws s3)

method : POST

url : http://localhost:3000/s3

body:{"operation": "delete","metadata": {"key": "my-test-file.txt"}}

i am getting below error

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

i am not sure what is the mistake i've done here, needed help on it

0 Answers
Related