dpcyx08288 2019-02-22 10:51
浏览 670

AWS S3预签名URL包含X-Amz-Security-Token

I am trying to create a presigned URL for a file in my S3 bucket using go sdk.

When I run the program from command line, I get the presigned URL which doesn't contain the X-Amz-Security-Token.

But if I use the same code from a lambda function, I always get the X-Amz-Security-Token in the URL.

I am not sure why this behaviour is different.

Here is the code -

func CreatePreSignedURL(bucketName string, path string) (string, error) {

    sess, err := session.NewSession(&aws.Config{
        Region: aws.String("us-east-1")},
    )

    svc := s3.New(sess)

    req, _ := svc.GetObjectRequest(&s3.GetObjectInput{
        Bucket: aws.String(bucketName),
        Key:    aws.String(path),
    })

    urlStr, err := req.Presign(60 * time.Minute)

    if err != nil {
        fmt.Println("error in generarting presigned URL is ", err)
        return urlStr, err
    }

    return urlStr, nil
}

The URL generated by lambda is quite long, for my application I am expecting a shorter URL without X-Amz-Security-Token

  • 写回答

1条回答 默认 最新

  • douhao2548 2019-02-22 11:30
    关注

    When the function is run in your command line, it generates pre-signed URLS with IAM credentials possibly stored in environment variables or in ~/.aws/config.

    Temporary credentials are assigned for the IAM role associated 1 with the function when invoked in AWS Lambda environment.

    AWS necessitates that requests made with temporary credentials include x-amz-security-token header. 2

    I don't find the length of the URL to be an issue here.

    If you like to keep a consistent behavior locally and in the Lambda function environment, an easy way to go is to set the AWS credentials in the environment of the Lambda function.

    评论

报告相同问题?

悬赏问题

  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao
  • ¥20 Vite 打包的 Vue3 组件库,图标无法显示
  • ¥15 php 同步电商平台多个店铺增量订单和订单状态
  • ¥15 关于logstash转发日志时发生的部分内容丢失问题
  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题