1

Client initialisation in Go:

type AWSClient struct {
    uploader   *manager.Uploader
    downloader *manager.Downloader
    psClient   *s3.PresignClient
    s3Client   *s3.Client
    sesClient  *sesv2.Client
}

func NewAWSClient() AWSClient {
    log.Println("Configuring AWS ...")

    cfg, err := config.LoadDefaultConfig(context.TODO())
    if err != nil {
        log.Fatal(err)
        panic("Error configuring AWS.")
    }

    s3Client := s3.NewFromConfig(cfg)
    sesClient := sesv2.NewFromConfig(cfg)

    return AWSClient{
        s3Client:   s3Client,
        uploader:   manager.NewUploader(s3Client),
        downloader: manager.NewDownloader(s3Client),
        psClient:   s3.NewPresignClient(s3Client),
        sesClient:  sesClient,
    }
}

And get signed URL using:

func (c AWSClient) GetPresignedURL(ctx context.Context, awsBucket string, key string, ttl time.Duration) (string, entity.Error) {
    logger := rctx.LoggerWithFn(ctx)

    input := &s3.GetObjectInput{
        Key:    &key,
        Bucket: &awsBucket,
    }

    resp, err := c.psClient.PresignGetObject(context.TODO(), input, s3.WithPresignExpires(ttl)) // 6 days expiry.
    if err != nil {
        logger.Log(p.Error, "error retrieving pre-signed object: "+err.Error())
        return "", entity.InternalError(err)
    }

    return resp.URL, nil
}

Even if I'm setting 6 days expiry, still the URL is expiring in 1 hour. Can anyone share some pointers to debug this scenario?

2
  • 2
    If you're running this in a Lambda, the presigned URL will use the session credentials, which have a fairly short lifespan. If you want a longer lived presigned URL, you'll need to use your own credentials that will have a longer lifecycle. Commented Jul 6 at 18:07
  • 1
    Signed URL expiration basically happens at the earlier of a) the signing credentials expiration and b) the supplied expiration date/time. Your situation is the former. Commented Jul 7 at 11:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.