AWS开发工具包是否会自动处理会话到期? [英] Does AWS SDK handles session expiry automatically?

查看:78
本文介绍了AWS开发工具包是否会自动处理会话到期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个客户端,以从RabbitMQ获取连续消息,并推送至AWS SQS服务.但是我不确定会话是否到期,如果会话到期,我们是否需要重新创建会话或AWS开发工具包自动处理它?<​​/p>

I am writing a client to get the continuous messages from RabbitMQ and pushing to AWS SQS service. But I'm not sure about the session expiry, If the session expires do we need to recreate the session or AWS SDK handles it automatically?

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,
    })

推荐答案

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

There is a default configuration for session expiration, but you can specify yours:

除了NewSession,您还可以使用以下方法创建会话NewSessionWithOptions.此功能可让您控制和覆盖如何通过代码创建会话,而不是仅由环境变量驱动.

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.

要提供配置文件时,请使用NewSessionWithOptions

Use NewSessionWithOptions when you want to provide the config profile

在选项"对象内,有一个用于更改默认到期时间的属性,默认为15分钟:

Inside of the Options object, there is an attribute for changing the default expiration time, by default is 15 minutes:

///当SDK的共享配置配置为承担角色时,此选项//可以用来设置STS凭证的有效期限.//如果未设置为默认值,则默认为15分钟//stscreds.AssumeRoleProvider.AssumeRoleDuration time.Duration

// 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/

这篇关于AWS开发工具包是否会自动处理会话到期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆