Search code examples
amazon-web-servicesgoamazon-dynamodbaws-sdkaws-sdk-go

How to overcome ResourceNotFoundException: Requested resource not found error in Go lang?


I am a beginner in Go lang and I am trying to establish a connection between Go lang and Dynamodb using AWS and insert data in dynamodb using an API written in Go lang. Any help would be appreciated.

Below is the code of what I am trying to do:

package main
import "fmt"	
import (  
        "github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/aws/credentials"
	"github.com/aws/aws-sdk-go/service/dynamodb"
        "github.com/user/dynamo_connect/data"
    )
func database_init() {
	
        var testCredentials = credentials.NewStaticCredentials("Access_key", "secret_key", "")
	sess, err := session.NewSession()
	svc := dynamodb.New(sess, &aws.Config{
		Region: aws.String("us-east-1"),
		Credentials: testCredentials,
	})
	resp, err := data.UploadForumData(svc)

	if err != nil {
		fmt.Println("An error occurred while writing to the Employee table")
		fmt.Println(err.Error())
	}
	fmt.Println(resp)

    }
func main() {
    database_init()
}

package data

import "github.com/aws/aws-sdk-go/service/dynamodb"
import "github.com/aws/aws-sdk-go/aws"

func UploadForumData(svc *dynamodb.DynamoDB) (*dynamodb.BatchWriteItemOutput, error) {
	params := &dynamodb.BatchWriteItemInput{
		RequestItems: map[string][]*dynamodb.WriteRequest{
			"employee": {
				&dynamodb.WriteRequest{
					PutRequest: &dynamodb.PutRequest{
						Item: map[string]*dynamodb.AttributeValue{
							"emp_id": {
								S: aws.String("2"),
							},
							"address": {
								S: aws.String("Wing Apartment"),
							},
							"emp_name": {
								S: aws.String("Kaushal"),
							},
						},
					},
				},
				
			},
		},
	}

	return svc.BatchWriteItem(params)
}

And this is the error which I am getting:

An error occurred while writing to the Employee table
ResourceNotFoundException: Requested resource not found
    status code: 400, request id: VIMB3ATCI6KPSJF1OOH2Q4VLKNVV4KQNSO5AEMVJF66Q9ASUAAJG
{

}

Can anyone help?


Solution

  • Actually, there is issue with my database connectivity.The region name which I have entered is incorrect. I have rechecked that using aws configure command and got it working.