AWS - How to make CRUD on S3

Asked

Viewed 118 times

0

I recently started studying AWS, and I’m feeling totally lost in the meaning of some things, how they work and what are their contexts for the application.

For example Keys (Keys), buckets (Bucket), RNA... Things like that.

Someone could tell me the meaning of them and exemplify some CRUD operations directly inside the AWS S3 ?

With the code below I can log in and copy things from the inbox (Inbox) to the outbox (outbox) but nothing more than that.

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 discovering the documentation I needed to make the operations simpler, but I don’t know how to use it properly...

https://docs.aws.amazon.com/sdkfornet1/latest/apidocs/html/T_Amazon_S3_AmazonS3Client.htm


I believe 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);
}

1 answer

3


The answer to your question is not so simple and may cause extensive discussion on how to better model/design/design a software solution to utilize an object storage structure (e.g. AWS S3, AWS Glazier). So the following is my interpretation of how you could follow your development revisiting some concepts and judging the best for your scenario.

The AWS S3 is a software solution for storing AWS objects, using AWS-specific concepts as a proprietary AWS solution.

Relational database (e.g. Oracle DB, Mysql DB) models its data using table and relationship concepts.

According to Wikipedia in Portuguese CRUD means:

CRUD (acronym for Create, Read, Update and Delete) are the four basic operations (creation, consultation, updating and destruction of data) used in relational databases (RDBMS) provided to system users.

The English version has a more interesting discussion about REST ( https://en.wikipedia.org/wiki/Create,_read,_update_and_delete ), S3 implements a REST api that can be interpreted as crud.

Following the definitions in English, CRUD is originally used as a software solution to access data within a relational database.

However S3 is not relational. Eventually you could use a CRUD approach with S3, however there are alternatives richer.

On the possibilities of what you can do with S3, the AWS documentation is extensive and of excellent quality, I suggest you start with https://aws.amazon.com/pt/s3/getting-started/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.