如何在Go语言中解决ResourceNotFoundException: Requested resource not found错误?

huangapple go评论99阅读模式
英文:

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

问题

我是Go语言的初学者,我正在尝试使用AWS在Go语言中建立Go语言和DynamoDB之间的连接,并使用Go语言编写的API将数据插入DynamoDB。任何帮助将不胜感激。

以下是我尝试做的代码:

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("在写入Employee表时发生错误")
		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)
}

这是我得到的错误:

在写入Employee表时发生错误
ResourceNotFoundException: 未找到请求的资源
状态码:400,请求ID:VIMB3ATCI6KPSJF1OOH2Q4VLKNVV4KQNSO5AEMVJF66Q9ASUAAJG
{

}

有人可以帮忙吗?

英文:

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:

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

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

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

    }
func main() {
    database_init()
}

<!-- end snippet -->

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-html -->

package data

import &quot;github.com/aws/aws-sdk-go/service/dynamodb&quot;
import &quot;github.com/aws/aws-sdk-go/aws&quot;

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

	return svc.BatchWriteItem(params)
}

<!-- end snippet -->

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?

答案1

得分: 5

实际上,我的数据库连接存在问题。我输入的地区名称是错误的。我使用aws configure命令重新检查了一下,并解决了这个问题。

英文:

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.

huangapple
  • 本文由 发表于 2016年11月17日 17:41:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/40651384.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定