File tree Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Expand file tree Collapse file tree 2 files changed +17
-2
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ require (
1010 github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.19.8
1111 github.com/aws/aws-sdk-go-v2/service/kms v1.45.4
1212 github.com/aws/aws-sdk-go-v2/service/s3 v1.88.2
13+ github.com/aws/aws-sdk-go-v2/service/sts v1.38.5
1314 github.com/google/uuid v1.6.0
1415 github.com/sirupsen/logrus v1.9.3
1516)
@@ -28,7 +29,6 @@ require (
2829 github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.8 // indirect
2930 github.com/aws/aws-sdk-go-v2/service/sso v1.29.4 // indirect
3031 github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.0 // indirect
31- github.com/aws/aws-sdk-go-v2/service/sts v1.38.5 // indirect
3232 github.com/aws/smithy-go v1.23.0 // indirect
3333 golang.org/x/sys v0.36.0 // indirect
3434)
Original file line number Diff line number Diff line change @@ -4,10 +4,11 @@ import (
44 "context"
55 "io"
66 "os"
7-
7+ "fmt"
88 "github.com/aws/aws-sdk-go-v2/config"
99 "github.com/aws/aws-sdk-go-v2/feature/s3/manager"
1010 "github.com/aws/aws-sdk-go-v2/service/s3"
11+ "github.com/aws/aws-sdk-go-v2/service/sts"
1112)
1213
1314var uploader * manager.Uploader
@@ -31,6 +32,20 @@ func init() {
3132
3233 // Create uploader
3334 uploader = manager .NewUploader (s3Client )
35+
36+ // Create STS client to get account ID
37+ stsClient := sts .NewFromConfig (cfg )
38+ // Get caller identity
39+ identity , err := stsClient .GetCallerIdentity (context .TODO (), & sts.GetCallerIdentityInput {})
40+ if err != nil {
41+ panic ("unable to get AWS caller identity: " + err .Error ())
42+ }
43+
44+ // Print complete identity
45+ fmt .Println ("AWS Caller Identity:" )
46+ fmt .Println ("Account ID:" , * identity .Account )
47+ fmt .Println ("ARN :" , * identity .Arn )
48+ fmt .Println ("UserID :" , * identity .UserId )
3449}
3550
3651// UploadToS3 sends data to S3
You can’t perform that action at this time.
0 commit comments