<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Alexi Tomala</title>
    <description>The latest articles on DEV Community by Alexi Tomala (@ajtomala).</description>
    <link>https://dev.to/ajtomala</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2666165%2Faada547c-8861-4767-a451-afbb6bc0c838.jpg</url>
      <title>DEV Community: Alexi Tomala</title>
      <link>https://dev.to/ajtomala</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ajtomala"/>
    <language>en</language>
    <item>
      <title>Uploading Files to Amazon S3 in ASP.NET Core with Razor Pages</title>
      <dc:creator>Alexi Tomala</dc:creator>
      <pubDate>Tue, 07 Jan 2025 21:12:43 +0000</pubDate>
      <link>https://dev.to/ajtomala/uploading-files-to-amazon-s3-in-aspnet-core-with-razor-pages-25n5</link>
      <guid>https://dev.to/ajtomala/uploading-files-to-amazon-s3-in-aspnet-core-with-razor-pages-25n5</guid>
      <description>&lt;p&gt;In this post we are going to explore how to upload file&lt;br&gt;
to our AWS S3 repository from an ASP.NET Core with Razor Pages app.&lt;/p&gt;

&lt;p&gt;In this case we make use of Visual studio for the creation and configuration of the solution:&lt;br&gt;
We select and create the Asp.Net project type.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhle4yedvvriwlx2qtimj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhle4yedvvriwlx2qtimj.png" alt="ASP.NET CORE Web App" width="653" height="80"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Created the solution we install the package nuget AWSSDK.S3&lt;br&gt;
from the AwsS3 library&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm938ade073rhyy5n15nl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm938ade073rhyy5n15nl.png" alt="AWSs3" width="800" height="105"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For this solution we are going to implement the repository pattern and start creating the interface for the file upload.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;namespace WebUploadFileS3.Interfaces
{
    public interface IRepositoryS3
    {
        Task&amp;lt;string&amp;gt; UploadFileAsync(IFormFile file);
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now create the class to implement the file upload method&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using WebUploadFileS3.Interfaces;
using Amazon.S3;
using Amazon.S3.Model;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using System.Collections.Generic;

namespace WebUploadFileS3.implementation
{
    public class RespositoryS3 : IRepositoryS3
    {
        private readonly IAmazonS3 _s3Client;
        private readonly string _bucketName;

        public RespositoryS3(IConfiguration configuration)
        {
            var accessKey = configuration["AWS:AccessKey"];
            var secretKey = configuration["AWS:SecretKey"];
            var region = configuration["AWS:Region"];
            _bucketName = configuration["AWS:BucketName"];

            _s3Client = new AmazonS3Client(accessKey, secretKey, Amazon.RegionEndpoint.GetBySystemName(region));
        }
        public async Task&amp;lt;string&amp;gt; UploadFileAsync(IFormFile file)
        {
            using var newMemoryStream = new MemoryStream();
            file.CopyTo(newMemoryStream);

            var request = new PutObjectRequest
            {
                BucketName = _bucketName,
                Key = file.FileName,
                InputStream = newMemoryStream,
                ContentType = file.ContentType,
                AutoCloseStream = true
            };
            await _s3Client.PutObjectAsync(request);
            return file.FileName;
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;En el archivo appsettings.json adicionar la credenciales de acceso al servicio AWS S3&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"AWS": {
    "AccessKey": "AccessKey",
    "SecretKey": "SecretKey",
    "BucketName": "bucketnet",
    "Region": "Region-1"
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Continue adding dependency in Program.cs or Startup file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using Microsoft.AspNetCore.Http.Features;
using WebUploadFileS3.implementation;
using WebUploadFileS3.Interfaces;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddRazorPages();

builder.Services.AddControllersWithViews();
builder.Services.AddScoped&amp;lt;IRepositoryS3, RespositoryS3&amp;gt;();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally in the razor page view create file upload form&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;div class="text-center"&amp;gt;

    @{ ViewData["Title"] = "Upload File"; }
    &amp;lt;h2&amp;gt;Upload File&amp;lt;/h2&amp;gt; 
    &amp;lt;form asp-controller="Home" asp-action="Upload" enctype="multipart/form-data" method="post"&amp;gt; 
        &amp;lt;div class="form-group"&amp;gt;
            &amp;lt;label for="file"&amp;gt;Select to file:&amp;lt;/label&amp;gt; 
            &amp;lt;input type="file" name="file" id="file" class="form-control" /&amp;gt; 
        &amp;lt;/div&amp;gt;
        &amp;lt;br /&amp;gt;
        &amp;lt;button type="submit" class="btn btn-primary"&amp;gt;Upload&amp;lt;/button&amp;gt;
    &amp;lt;/form&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Check out the source code in: &lt;a href="https://dev.tourl"&gt;https://github.com/ajtomala/WebUploadFileS3&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Please let me know your questions&lt;/p&gt;

</description>
      <category>aws</category>
      <category>aspdotnet</category>
      <category>tutorial</category>
      <category>s3</category>
    </item>
    <item>
      <title>The Unsung Hero of DevOps AWS X-Ray</title>
      <dc:creator>Alexi Tomala</dc:creator>
      <pubDate>Mon, 06 Jan 2025 21:02:02 +0000</pubDate>
      <link>https://dev.to/ajtomala/the-unsung-hero-of-devops-aws-x-ray-4bm0</link>
      <guid>https://dev.to/ajtomala/the-unsung-hero-of-devops-aws-x-ray-4bm0</guid>
      <description>&lt;p&gt;AWS X-Ray makes it easy for developers to analyze and debug distributed and production applications, especially those built with a microservices architecture. Find out more at &lt;a href=""&gt;https://aws.amazon.com/xray/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Getting into the nitty-gritty, troubleshooting bugs in a production environment can be a real challenge. Even when end users are not directly affected, &lt;br&gt;
there is often great pressure to identify and fix problems quickly. One of the most effective tools to facilitate this task is AWS X-Ray.&lt;br&gt;
In the devops environment making use of X-Ray is of super benefits since it will allow you to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Complete Visibility:&lt;/strong&gt; X-Ray provides a detailed map of your application services, showing how they interact with each other. This is essential for DevOps teams that need to quickly identify latency issues or system failures.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Bottleneck Identification:&lt;/strong&gt; With X-Ray, you can track application performance and discover where the bottlenecks are. This allows you to optimize the components that really need attention, improving the overall performance of your application.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Continuous Monitoring:&lt;/strong&gt; AWS X-Ray enables continuous monitoring of your application, which means you can detect problems in real time and take corrective action before they affect end users.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h4&gt;
  
  
  One of the AWS X-Ray Use Cases in DevOps that I'm reviewing is:
&lt;/h4&gt;

&lt;p&gt;&lt;strong&gt;Rapid Troubleshooting&lt;/strong&gt; : Let's imagine your application is experiencing slow response times. With X-Ray, you get to track each request and see where the delays are occurring. This allows you to quickly identify whether the problem is in the code, the database, or an external service.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Application Optimization&lt;/strong&gt;: The data collected by X-Ray can help you understand how your application resources are being used. You can use this information to optimize the use of CPU, memory and other resources, resulting in better performance and lower operating costs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Improved User Experience:&lt;/strong&gt; By identifying and resolving problems before they impact end users, you can improve the user experience. X-Ray helps you maintain high levels of availability and performance, which is critical in today's competitive environment.&lt;/p&gt;

&lt;p&gt;Implementing X-Ray in your DevOps environment is easy. Here is a quick guide in .NET:&lt;/p&gt;

&lt;p&gt;Installing the SDK: Make sure your application is using the AWS X-Ray SDK. You can easily install it through NuGet for .NET applications.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Install-Package AWSSDK.XRay
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Code Instrumentation: Add the necessary calls in your code to send data to X-Ray. This may involve changes to your code to capture request and response data.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;using Amazon.XRay.Recorder.Core; 
using Amazon.XRay.Recorder.Handlers.AwsSdk; 
public class Startup
 { 
   public void ConfigureServices(IServiceCollection services) 
   { 
     AWSXRayRecorder.InitializeInstance(); 
    AWSSDKHandler.RegisterXRayForAllServices(); 
   } 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
AWS X-Ray is an essential tool for DevOps teams looking to keep their distributed applications running optimally. With its ability to provide complete visibility,&lt;br&gt;
 identify bottlenecks, and enable continuous monitoring for any DevOps strategy. &lt;/p&gt;

</description>
      <category>aws</category>
      <category>xray</category>
      <category>devops</category>
      <category>dotnet</category>
    </item>
  </channel>
</rss>
