I want to bring some "guide" how to use AWS SDK .NET, especially using S3. Simple code that you can follow, please navigate to here, in there you will use .NET console.
Preparation
Please install .NET first. You can choose either .NET 5 or .NET Core 3.1.
Prepare your project. You can use this command. (if you are already have the project, just skip this step)
dotnet new webapi -o AWSS3Example
Note: In case you can't find the webapi (when use .NET 6), you can use template from .NET 3.1 since in this article using existing project and the existing project using .NET 3.1 and only change the TargetFramework to .net6.0.
Add AWS SDK S3 to your project. You can use this command.
I want to write the interface for writing file to S3, so if AWS SDK S3 have major changed, you only change the implementation of the interface. I will write the interface at AWSS3Example/Services/AWS/IAWSS3Service.cs.
usingAmazon.S3;usingAWSS3Example.Services.AWS;// ... the rest of another usingusingMicrosoft.AspNetCore.Builder;usingMicrosoft.AspNetCore.Hosting;usingMicrosoft.EntityFrameworkCore;usingMicrosoft.Extensions.Configuration;usingMicrosoft.Extensions.DependencyInjection;usingMicrosoft.Extensions.Hosting;namespaceAWSS3Example{publicclassStartup{publicStartup(IConfigurationconfiguration){Configuration=configuration;}publicIConfigurationConfiguration{get;}// This method gets called by the runtime. Use this method to add services to the container.publicvoidConfigureServices(IServiceCollectionservices){// the rest of another register service ...services.AddScoped<IAWSS3Service,AWSS3Service>();services.AddAWSService<IAmazonS3>();// the rest of another register service ...services.AddControllers();}// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.publicvoidConfigure(IApplicationBuilderapp,IWebHostEnvironmentenv){// the rest of your configure, no need to modify this...}}}
Run your project.
dotnet run --project AWSS3Example
Test your API
Note: In my case, I use different path, so please use the path that you define at Controller.
NET Core API Boilerplate (BervProject.WebApi.Boilerplate)
Net Core Web API Boilerplate for My Project
.NET Version
8.0
Build Status
Github Action
Azure Pipelines
Codecov
LICENSE
MIT
MIT License
Copyright (c) 2019 Bervianto Leo Pratama's Personal Projects
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND