我是Go lang的初学者,我正在尝试使用AWS在Go lang和Dynamodb之间建立连接,并使用Go lang编写的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("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)
}

这是我得到的错误:
An error occurred while writing to the Employee table
ResourceNotFoundException: Requested resource not found
status code: 400, request id: VIMB3ATCI6KPSJF1OOH2Q4VLKNVV4KQNSO5AEMVJF66Q9ASUAAJG
{
}
有人可以帮忙吗?
答案 0 :(得分:1)
实际上,我的数据库连接存在问题。我输入的区域名称不正确。我已经使用aws configure命令重新检查并使其正常工作。