douzhan8303 2019-05-14 17:07
浏览 398
已采纳

MissingRegion:在golang和AWS SNS中找不到区域配置

I am new to Golang and AWS. I am trying to send SMS using AWS SNS. I have set Environment variable First then try send SMS.

export AWS_ACCESS_KEY_ID=AKIAIOSFODN..
export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEM..
export AWS_DEFAULT_REGION=us-west-2

I tried to debug where i am getting wrong But always getting error MissingRegion: could not find region configuration

package main

import (
    "fmt"

    "github.com/aws/aws-sdk-go/aws"
    "github.com/aws/aws-sdk-go/aws/session"
    "github.com/aws/aws-sdk-go/service/sns"
)

func main() {
    fmt.Println("creating session")
    sess := session.Must(session.NewSession())
    fmt.Println("session created")
    svc := sns.New(sess)
    fmt.Println("service created")
    params := &sns.PublishInput{
        Message: aws.String("testing 123"),         
        PhoneNumber: aws.String("+14445556666"),    
    }
    resp, err := svc.Publish(params)

    if err != nil {
        fmt.Println(err.Error())
        return
    }
    fmt.Println(resp)
}

I am trying to do this since last 2 days.Please help me where i am going wrong.

  • 写回答

1条回答 默认 最新

  • dtlzdofl66441 2019-05-14 17:13
    关注

    You have to configure the SDK. To set just the region you would do something like sess, err := session.NewSession(&aws.Config{ Region: aws.String("us-west-2")}, )

    You can see full details on config here: https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/configuring-sdk.html

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

报告相同问题?

悬赏问题

  • ¥15 flutter 编译web端出错,如何解决?
  • ¥20 使用AT89C51微控制器和MAX7219驱动器来实现0到99秒的秒表计数,有开始和暂停以及复位功能,请写出C语言程序
  • ¥15 51单片机 双路ad同步采样
  • ¥15 使用xdocreport 生成word
  • ¥15 请教怎么用MATLAB求坐标
  • ¥15 gradle整合es,在创建索引时报错
  • ¥15 关于模型训练的一个问题
  • ¥15 装了几千台服务器从来没遇到这种问题,哎看下哪位帮我解决吧
  • ¥15 单片机程序上的困难问题
  • ¥15 请教某软件缓存Ts文件破解合并mp4的方法