AWS SDK 是否自动处理会话过期?

Does AWS SDK handles session expiry automatically?

我正在编写一个客户端以从 RabbitMQ 获取连续消息并推送到 AWS SQS 服务。但我不确定会话是否过期,如果会话过期,我们是否需要重新创建会话或 AWS SDK 自动处理它?

log.Printf("PPU Message Broker: Pushing messages to SQS")
    sess, err := session.NewSession(&aws.Config{
        Region:      aws.String("us-east-1"),
        //Credentials: credentials.NewSharedCredentials("", "sqs_user"),
    })
    _, err = sess.Config.Credentials.Get()
    if err != nil {
        log.Fatalf("PPU Message Broker: Credentails Failed")
    }
    svc := sqs.New(sess)    
    result, err := svc.SendMessage(&sqs.SendMessageInput{
        MessageBody:    aws.String(string(data)),
        MessageGroupId: aws.String("TestGroup"),
        QueueUrl:       &qURL,
    })

更新的答案:

刚注意到问题是关于 AWS SDK for Go 的。

来自 AWS SDK for Go 文档:https://docs.aws.amazon.com/sdk-for-go/api/aws/credentials/#Credentials.Get

func (*Credentials) Get

func (c *Credentials) Get() (Value, error)

Get returns the credentials value, or error if the credentials Value failed to be retrieved.

Will return the cached credentials Value if it has not expired. If the credentials Value has expired the Provider's Retrieve() will be called to refresh the credentials.

If Credentials.Expire() was called the credentials Value will be force expired, and the next call to Get() will cause them to be refreshed. 

原回答:

来自 AWS Javascript 位于 https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Credentials.html#get-property

的 SDK 文档
get(callback) ⇒ void

Gets the existing credentials, refreshing them if they are not yet loaded or have expired. Users should call this method before using refresh(), as this will not attempt to reload credentials when they are already loaded into the object.

会话过期有一个默认配置,但您可以指定您的配置:

In addition to NewSession, you can create sessions using NewSessionWithOptions. This function allows you to control and override how the session will be created through code, instead of being driven by environment variables only.

Use NewSessionWithOptions when you want to provide the config profile

在Options对象里面,有一个属性可以改变默认过期时间,默认是15分钟:

// When the SDK's shared config is configured to assume a role this option // may be provided to set the expiry duration of the STS credentials. // Defaults to 15 minutes if not set as documented in the // stscreds.AssumeRoleProvider. AssumeRoleDuration time.Duration

https://docs.aws.amazon.com/sdk-for-go/api/aws/session/