Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does AWS SDK handles session expiry automatically?

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,
    })
like image 972
Srikanth Avatar asked Jan 20 '26 10:01

Srikanth


1 Answers

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

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

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

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

like image 194
Damian229 Avatar answered Jan 22 '26 23:01

Damian229



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!