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