An Uncomplicated Path to AWS with Golang
Lucid step-by-step process to get started with AWS using Golang
AWS CLI provides a very convenient interface to communicate with your AWS Account.
All you need to do is head over to your AWS account and fetch AWS Access Key ID, AWS Secret Access Key
Run AWS configure and your local setup is configured
~ aws configure
AWS Access Key ID [None]: ******
AWS Secret Access Key [None]: *******
Default region name [None]: [preferred region: eg us-west-2]
Default output format [None]: [json/yaml/text/yaml-stream/table]
Set up our S3Client to communicate with S3 account
import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/s3"
)
Create S3 Client
sess, err := session.NewSession(&aws.Config{
Region: aws.String("us-west-2")},
)
// Create S3 service client
svc := s3.New(sess)
Push an Object file to your bucket with S3Client's PutObject method
Make sure to hit [Ctrl+Enter] in your IDE to get the definition and explore the argument options!
func FileUpload(filename string) error {
params := s3.PutObjectInput{
Bucket: aws.String("test-bucket"),
Key: aws.String(filename),
Body: input,
}
_, err := svc.PutObject(context.TODO(),¶ms)
if err!= nil {
return err
}
return nil
}
Head over to your console to verify the uploaded file.
Hope the simplicity helps you understand the flow, comment for any doubts ;)
Cheers!