Created
December 20, 2017 04:00
-
-
Save 2matzzz/a0b916c9aa5a9cb98af80da8eeb03339 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"net/url" | |
"github.com/aws/aws-sdk-go/aws" | |
"github.com/aws/aws-sdk-go/aws/credentials/stscreds" | |
"github.com/aws/aws-sdk-go/aws/session" | |
"github.com/aws/aws-sdk-go/service/s3" | |
) | |
func main() { | |
sess := session.Must(session.NewSession()) | |
creds := stscreds.NewCredentials( | |
sess, | |
"arn:aws:iam::ACCOUNT_ID:role/YOUR_ROLE_NAME", | |
func(p *stscreds.AssumeRoleProvider) { | |
p.ExternalID = aws.String("EXTERNAL_ID") | |
}, | |
) | |
svc := s3.New(sess, &aws.Config{Credentials: creds}) | |
source := url.QueryEscape("SRC_BUCKET_NAME/SRC_OBJECT_KEY") | |
params := &s3.CopyObjectInput{} | |
params.SetBucket("DEST_BUCKET_NAME") | |
params.SetKey("DEST_OBJECT_KEY") | |
params.SetCopySource(source) | |
req, resp := svc.CopyObjectRequest(params) | |
err := req.Send() | |
if err == nil { | |
fmt.Println(resp) | |
} else { | |
fmt.Println(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment