1
0
mirror of https://github.com/astaxie/cookbook.git synced 2025-08-08 09:42:04 +03:00

Doc: This patch will modify aws-sdk-go example and fix typos from aws-sdk-php doc. (#69)

This commit is contained in:
koolhead17
2016-08-17 15:38:21 -07:00
committed by Harshavardhana
parent c1ee1be820
commit 1b1d0fb757
4 changed files with 107 additions and 104 deletions

View File

@@ -14,7 +14,6 @@ Note: You can also refer to [Awesome Minio](https://github.com/minio/awesome-min
- [Running Deis Workflow with Minio](./docs/running-deis-workflow-with-minio.md) - [Running Deis Workflow with Minio](./docs/running-deis-workflow-with-minio.md)
- [AWS CLI with Minio](./docs/aws-cli-with-minio.md) - [AWS CLI with Minio](./docs/aws-cli-with-minio.md)
- [AWS Go SDK for Minio](./docs/aws-go-sdk-for-minio.md)
- [Running Minio in Docker](./docs/running-minio-in-docker.md) - [Running Minio in Docker](./docs/running-minio-in-docker.md)
- [Running Minio in FreeNAS](./docs/running-minio-in-freenas.md) - [Running Minio in FreeNAS](./docs/running-minio-in-freenas.md)
- [Store MongoDB Backups in Minio](./docs/store-mongodb-backups-in-minio.md) - [Store MongoDB Backups in Minio](./docs/store-mongodb-backups-in-minio.md)
@@ -32,3 +31,4 @@ Note: You can also refer to [Awesome Minio](https://github.com/minio/awesome-min
- [Upload via Browser with PreSignedPut](./docs/presigned-put-upload-via-browser.md) - [Upload via Browser with PreSignedPut](./docs/presigned-put-upload-via-browser.md)
- [How to use Cyberduck with Minio](./docs/how-to-use-cyberduck-with-minio.md) - [How to use Cyberduck with Minio](./docs/how-to-use-cyberduck-with-minio.md)
- [How to use AWS SDK for PHP with Minio Server](./docs/aws-sdk-for-php-with-minio.md) - [How to use AWS SDK for PHP with Minio Server](./docs/aws-sdk-for-php-with-minio.md)
- [How to use AWS SDK for Go with Minio Server](./docs/aws-sdk-for-go-with-minio.md)

View File

@@ -1,101 +0,0 @@
# AWS Go SDK for Minio Server [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/minio/minio?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
`aws-sdk-go` is the official AWS SDK for the Go programming language. In this recipe we will learn how to use `aws-sdk-go` with Minio server.
## 1. Prerequisites
Install Minio Server from [here](http://docs.minio.io/docs/minio).
## 2. Installation
Install `aws-sdk-go` by:
```sh
$ go get github.com/aws/aws-sdk-go/...
```
## 3. Example
Access credentials shown in this example belong to https://play.minio.io:9000.
These credentials are open to public. Feel free to use this service for testing and development. Replace with your own Minio keys in deployment.
List all buckets on minio server using aws-sdk-go.
```go
package main
import (
"fmt"
"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"
)
func main() {
newSession := session.New()
// Configure to use Minio Server
s3Config := &aws.Config{
Credentials: credentials.NewStaticCredentials("Q3AM3UQ867SPQQA43P2F", "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG", ""),
Endpoint: aws.String("https://play.minio.io:9000"),
Region: aws.String("us-east-1"),
DisableSSL: aws.Bool(true),
S3ForcePathStyle: aws.Bool(true),
}
// Create an S3 service object in the default region.
s3Client := s3.New(newSession, s3Config)
cparams := &s3.CreateBucketInput{
Bucket: aws.String("newbucket"), // Required
}
// Create a new bucket using the CreateBucket call.
_, err := s3Client.CreateBucket(cparams)
if err != nil {
// Message from an error.
fmt.Println(err.Error())
return
}
var lparams *s3.ListBucketsInput
// Call the ListBuckets() Operation
resp, err := s3Client.ListBuckets(lparams)
if err != nil {
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
```
## 3. Run the Program
```sh
$ go run aws-sdk-minio.go
{
Buckets: [{
CreationDate: 2015-10-22 01:46:04 +0000 UTC,
Name: "newbucket"
}],
Owner: {
DisplayName: "minio",
ID: "minio"
}
}
```

View File

@@ -0,0 +1,104 @@
# How to use AWS SDK for Go with Minio Server [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/minio/minio?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
`aws-sdk-go` is the official AWS SDK for the Go programming language. In this recipe we will learn how to use `aws-sdk-go` with Minio server.
## 1. Prerequisites
Install Minio Server from [here](http://docs.minio.io/docs/minio).
## 2. Installation
Install ``aws-sdk-go`` from AWS SDK for Go official docs [here](https://aws.amazon.com/sdk-for-go/)
## 3. Example
Please replace ``Endpoint``,``Credentials``, ``Bucket`` with your local setup in this ``example.go`` file.
Example below shows putObject and getObject operations on Minio server using aws-sdk-go.
```go
package main
import (
"fmt"
"os"
"strings"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/credentials"
"github.com/aws/aws-sdk-go/service/s3/s3manager"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
)
func main() {
bucket := aws.String("newbucket")
key := aws.String("testobject")
// Configure to use Minio Server
s3Config := &aws.Config{
Credentials: credentials.NewStaticCredentials("H5K8172RVM311Q2XFEHX", "5bRnl3DGhNM+fRBMxOii11k8iT78cNSIfoqnJfwC", ""),
Endpoint: aws.String("http://localhost:9000"),
Region: aws.String("us-east-1"),
DisableSSL: aws.Bool(true),
S3ForcePathStyle: aws.Bool(true),
}
newSession := session.New(s3Config)
s3Client := s3.New(newSession)
cparams := &s3.CreateBucketInput{
Bucket: bucket, // Required
}
// Create a new bucket using the CreateBucket call.
_, err := s3Client.CreateBucket(cparams)
if err != nil {
// Message from an error.
fmt.Println(err.Error())
return
}
// Upload a new object "testobject" with the string "Hello World!" to our "newbucket".
_, err = s3Client.PutObject(&s3.PutObjectInput{
Body: strings.NewReader("Hello from Minio!!"),
Bucket: bucket,
Key: key,
})
if err != nil {
fmt.Printf("Failed to upload data to %s/%s, %s\n", *bucket, *key, err.Error())
return
}
fmt.Printf("Successfully created bucket %s and uploaded data with key %s\n", *bucket, *key)
// Retrieve our "testobject" from our "newbucket" and store it locally in "testobject_local".
file, err := os.Create("testobject_local")
if err != nil {
fmt.Println("Failed to create file", err)
return
}
defer file.Close()
downloader := s3manager.NewDownloader(newSession)
numBytes, err := downloader.Download(file,
&s3.GetObjectInput{
Bucket: bucket,
Key: key,
})
if err != nil {
fmt.Println("Failed to download file", err)
return
}
fmt.Println("Downloaded file", file.Name(), numBytes, "bytes")
}
```
## 4. Run the Program
```sh
$ go run example.go
Successfully created bucket newbucket and uploaded data with key testobject
Downloaded file testobject_local 18 bytes
```

View File

@@ -16,7 +16,7 @@ Install `aws-sdk-php` from AWS SDK for PHP official docs [here](https://docs.aws
Please replace ``endpoint``,``credentials``, ``Bucket`` with your local setup in this ``example.php`` file. Please replace ``endpoint``,``credentials``, ``Bucket`` with your local setup in this ``example.php`` file.
List all buckets on Minio server using aws-sdk-php. Example below shows putObject and getObject operations on Minio server using aws-sdk-php.
```php ```php
@@ -58,7 +58,7 @@ echo $retrive['Body'];
``` ```
## 3. Run the Program ## 4. Run the Program
```sh ```sh
$ php example.php $ php example.php