Oracle Cloud Infrastructure offers an S3 compatible API for object storage.
This example will show you how to use it with the AWS Go SDK
Endpoint
%s.compat.objectstorage.%s.oraclecloud.com (tenancy, region)
Configure the client with your access key and secret access key
func createClient(tenancy, region, accessKey, secretAccessKey string) *s3.S3 {
endpoint := fmt.Sprintf("%s.compat.objectstorage.%s.oraclecloud.com", tenancy, region)
s3Config := &aws.Config{
Credentials: credentials.NewStaticCredentials(accessKey, secretAccessKey, ""),
Endpoint: aws.String(endpoint),
Region: aws.String(region),
S3ForcePathStyle: aws.Bool(true),
}
newSession := session.New(s3Config)
return s3.New(newSession)
}
func main() {
accessKey := "ocid1.credential.oc1...."
secretAccessKey := "M4MivGH9Z0ILEgwpoz60rmg..."
s3Client := createClient("spinnaker", "eu-frankfurt-1", accessKey, secretAccessKey)
}
Create a bucket
file, err := os.Open("README.md")
if err != nil {
return
}
_, err = s3Client.PutObject(&s3.PutObjectInput{
// io.ReadSeeker (ReadSeeker is the interface that groups the basic Read and Seek methods)
Body: file,
Bucket: aws.String("backups"),
Key: aws.String("hello"),
})
if err != nil {
fmt.Printf("Failed to upload: %s", err.Error())
return
}