AWS - How to do CRUD on S3

0

Recently I started to study AWS, and I'm feeling totally lost about the meaning of some things, how they work and what their contexts are for the application.

For example Keys, Buckets, RNA ... Things like that.

Could anyone tell me the meaning of them and exemplify some CRUD operations directly within AWS S3?

With the code below I can log in and copy things from the inbox to the outbox but nothing more.

public class FileBatch
{

    private readonly string[] _supportedImageTypes = new string[] { ".png", ".jpg", ".jpeg" };
    private readonly AmazonS3Client _s3Client;

    public FileBatch()
    {
        AmazonS3Config config = new AmazonS3Config();



        _s3Client = new AmazonS3Client(
            "00000000000000000000", //ID_Access
            "0000000000000000000000000000000000000000", //Key_Access
            config
        );


    }

    public async Task OcrHandler(S3Event s3Event, ILambdaContext context)
    {


 foreach (var record in s3Event.Records)
        {

            if (!Regex.IsMatch(record.S3.Object.Key, @"inbox/.*"))
            {
                continue;
            }

Console.WriteLine(
                $"A imagem '{record.S3.Bucket.Name}:{record.S3.Object.Key}' será processada e copiada para a caixa de saída");

            var outputKey = record.S3.Object.Key.Replace("inbox/", "outbox/");

            CopyObjectRequest request = new CopyObjectRequest
            {
                SourceBucket = record.S3.Bucket.Name,
                SourceKey = record.S3.Object.Key,
                DestinationBucket = record.S3.Bucket.Name,
                DestinationKey = outputKey
            };
            CopyObjectResponse response = await _s3Client.CopyObjectAsync(request);

        }
    }

I think I ended up finding the documentation I needed to make the operations simpler, but I do not know how to use it right ...

link

I think this is the way to create things inside the AWS folders

// Create a client
AmazonS3Client client = new AmazonS3Client();

// Create a PutObject request
PutObjectRequest request = new PutObjectRequest
{
    BucketName = "SampleBucket",
    Key = "Item1",
};

using (FileStream stream = new FileStream("contents.txt", FileMode.Open))
{
    request.InputStream = stream;

    // Put object
    PutObjectResponse response = client.PutObject(request);
}
    
asked by anonymous 24.11.2018 / 00:59

0 answers