duancan1950 2016-11-17 09:41
浏览 175
已采纳

如何克服ResourceNotFoundException: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?

</div>
  • 写回答

1条回答 默认 最新

  • douwudie8060 2016-11-19 11:04
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器