0

Basic express application shown below, AWS credentials redacted, when I run this locally using node index.js it works perfectly and the record is created on the live DB table.

However, when I push into my ECS cluster I get the following error:

{"success":false,"response":"Error: Unable to connect to instance metadata service"}

Any suggestions on how to diagnose this or better troubleshoot.

Index.js

const express = require('express')
const app = express()
const port = 80

const AWS = require("aws-sdk");

AWS.config.update({
    region: "eu-west-2",
    accessKeyId: 'ACCESS KEY',
    secretAccessKey: 'SECRET KEY',
});

const uuidv4 = require('uuid');

app.get('/raise/create', (req, res) => {
    const {DynamoDBClient, PutItemCommand} = require("@aws-sdk/client-dynamodb")

    const REGION = "eu-west-2";

    const params = {
        TableName: "table name",
        Item: {
            uuid: {S: uuidv4.v4()}
        }
    }

    const dbclient = new DynamoDBClient({region: REGION});

    const run = async () => {
        try {
            const data = await dbclient.send(new PutItemCommand(params));
            res.send({
                success: true,
                response: data.toString()
            });
        } catch (err) {
            res.send({
                success: false,
                response: err.toString()
            });
        }
    }

    run();
});

app.listen(port, () => {
    console.log(`Example app listening at http://localhost:${port}`)
})

EDIT

I am running via Fargate if it makes a difference

Lewis Smith
  • 1,271
  • 1
  • 14
  • 39
  • Have you [troubleshoot](https://stackoverflow.com/a/65789538/14843902) checked for any network connection reject logs ? – amitd Feb 11 '21 at 15:45
  • Don't have an answer but if you haven't already I would at least verify that you are able to ping your instance and get back its meta through your shell. – Tony Feb 11 '21 at 15:49
  • I'm running on Fargate so nothing really to do that on – Lewis Smith Feb 11 '21 at 15:53
  • Are you getting this message after you push it to your cluster or when the 'create' route gets hit? – Tony Feb 14 '21 at 21:44

0 Answers0