英文:
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 "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()
}
<!-- end snippet -->
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-html -->
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)
}
<!-- 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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论