Generate a Pre-Signed URL with golang

I wrote the code to issue PreSignedUrl in Golang, so I will leave it.

package main

import (
	"context"
	"fmt"
	"time"
    "os"


	"github.com/aws/aws-sdk-go/aws"
	"github.com/aws/aws-sdk-go/aws/credentials"
	"github.com/aws/aws-sdk-go/aws/session"
	"github.com/aws/aws-sdk-go/service/s3"
)

	//S3 connection information
	accessKey := os.Getenv("AWS_ACCSESS_KEY")
	secretKey := os.Getenv("AWS_SECRET_KEY")
	region := aws.String(os.Getenv("CUEE_DB_REGION"))

	creds := credentials.NewStaticCredentials(accsessKey, secretKey, "")
	session := session.Must(session.NewSession(&aws.Config{
		Credentials: creds,
		Region:      region,
	}))
	svc := s3.New(session)
	c, _ := svc.PutObjectRequest(&s3.PutObjectInput{
		Bucket: aws.String("Bucket name"),
		Key:    aws.String("/diectory/filename"),
	})

	url, err := c.Presign(15 * time.Minute)
	if err != nil {
		fmt.Println("error presigning request", err)
		return nil, err
	}

	fmt.Println(url)
}

You can set the expiration date here

url, err := c.Presign(15 * time.Minute)

official https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/s3-example-presigned-urls.html

You can upload by including the file in Body and accessing the issued URL

Recommended Posts

Generate a Pre-Signed URL with golang
Generate a normal distribution with SciPy
[Python] Generate a password with Slackbot
Generate S3 signed URL with boto
Generate all files with a specific extension
Issue a signed URL with AWS SQS
Getting Started with Golang 2
A4 size with python-pptx
Generate a random sentence from your tweet with trigram
Getting Started with Golang 1
A story about trying a (Golang +) Python monorepo with Bazel
Getting Started with Golang 3
Call bash with golang
Getting Started with Golang 4
Decorate with a decorator
[Golang] A program that determines the turn with random numbers
Draw a graph with NetworkX
Getting Started with PKI with Golang ―― 4
Try programming with a shell!
Generate XML (RSS) with Python
Randomly generate a complete permutation
Create a homepage with django
Generate URL query from JSON
Using a printer with Debian 10
Make a fortune with Python
Create a heatmap with pyqtgraph
Create a directory with python
A little stuck with chainer
Draw a graph with networkx
Easily cProfile with a decorator
Generate Pokemon with Deep Learning
Make a fire with kdeplot
Create a program that can generate your favorite images with Selenium
Define the reaction pattern with SMARTS with RDKit and generate a reactant
Batch download images from a specific URL with python Modified version
Get the URL of a JIRA ticket created with the jira-python library
Generate physically sturdy shapes with GAN and print with a 3D printer