Junior — Middle
What methods can you use to transfer data to cloud infrastructure?
sobes.tech AI
Answer from AI
Data transfer to cloud infrastructure can be carried out in several ways:
- HTTP/HTTPS requests — sending data via the cloud provider's REST API using standard HTTP clients.
- Cloud provider SDKs — using official libraries (e.g., AWS SDK, Google Cloud SDK) for programmatic data upload.
- CLI tools — command-line utilities provided by cloud services (e.g.,
aws cli,gcloud) for transferring files and data. - File transfer protocols — such as SFTP, SCP, if the cloud infrastructure supports SSH access.
- Message queues and streaming — using services like Kafka, RabbitMQ, or cloud queues for streaming data transfer.
Example of uploading a file to AWS S3 using Go SDK:
import (
"context"
"fmt"
"os"
"github.com/aws/aws-sdk-go-v2/config"
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
)
func uploadFile(bucket, key, filename string) error {
cfg, err := config.LoadDefaultConfig(context.TODO())
if err != nil {
return err
}
client := s3.NewFromConfig(cfg)
file, err := os.Open(filename)
if err != nil {
return err
}
defer file.Close()
_, err = client.PutObject(context.TODO(), &s3.PutObjectInput{
Bucket: &bucket,
Key: &key,
Body: file,
ACL: types.ObjectCannedACLPrivate,
})
return err
}