Can we use dynamodb without nodejs ?

0

Hello guys, how are you I am a beginner in AWS and I wanna know can I use plain JavaScript to store values and manipulate them using DynamoDB.

const { DynamoDBClient } = require('@aws-sdk/client-dynamodb');
const { DynamoDBDocument } = require('@aws-sdk/lib-dynamodb');
// Create service client module using ES6 syntax.
//import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
// Set the AWS Region.
const REGION = "ap-south-1"; //e.g. "us-east-1"
// Create an Amazon DynamoDB service client object.
const ddbClient = new DynamoDBClient({ region: REGION });


// Import required AWS SDK clients and commands for Node.js
import { CreateTableCommand } from "@aws-sdk/client-dynamodb";


// Set the parameters
const params3 = {
    AttributeDefinitions: [
      {
        AttributeName: "Season", //ATTRIBUTE_NAME_1
        AttributeType: "N", //ATTRIBUTE_TYPE
      },
      {
        AttributeName: "Episode", //ATTRIBUTE_NAME_2
        AttributeType: "N", //ATTRIBUTE_TYPE
      },
    ],
    KeySchema: [
      {
        AttributeName: "Season", //ATTRIBUTE_NAME_1
        KeyType: "HASH",
      },
      {
        AttributeName: "Episode", //ATTRIBUTE_NAME_2
        KeyType: "RANGE",
      },
    ],
    ProvisionedThroughput: {
      ReadCapacityUnits: 1,
      WriteCapacityUnits: 1,
    },
    TableName: "TEST_TABLE", //TABLE_NAME
    StreamSpecification: {
      StreamEnabled: false,
    },
  };
  
const run = async () => {
    try {
      const data = await ddbClient.send(new CreateTableCommand(params3));
      console.log("Table Created", data);
      return data;
    } catch (err) {
      console.log("Error", err);
    }
  };
  run();

and I am facing this error- Enter image description here

above is a code and output image in which I am facing credentials error. Please someone guide me where I am doing wrong. Thanks for your time and guidance.

질문됨 2년 전391회 조회
1개 답변
2
수락된 답변

You seem to be missing credentials. You haven't mentioned where you are running your application from, if its from your local machine you can set up the credentials using AWS Configure. This will allow your code pick up credentials and interact with DynamoDB, so long as the credentials belong to a user who has DynamoDB access. More on Identity and Access Management here.

If you're using an AWS service to host the code such as Lambda, then ensure you attach an IAM execution role to the service so it has permissions. Here is an example for Lambda but the same goes for EC2 or other services.

profile pictureAWS
전문가
답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠