Monday, June 27, 2022

How to Install Azure CLI on Windows?

 The Azure Command-Line Interface (CLI) is a cross-platform command-line tool that can be installed locally on Windows computers. You can use the Azure CLI for Windows to connect to Azure and execute administrative commands on Azure resources. The Azure CLI for Windows can also be used from a browser through the Azure Cloud Shell or run from inside a Docker container.

Step 1:- Download Azure CLI from the Latest release of the Azure CLI 


Step 2:- Install the Azure CLI in your system

Step 3:- verified the azure CLI :- Go To search and found Microsoft azure command prompt



When cmd is open type az and ENTER.


Thank you! Happy Learning. 

 
I have referer to The Microsoft site for more references please visit Microsoft-Site.




Wednesday, June 15, 2022

Configuring the AWS SDK for .NET with .NET Core

 In this post, we will only set up SDKs for S3 and SQS services, but the procedure will be the same for any other AWS service you want to use in a .NET application.

So, let's get started.

Tools & Frameworks

We will be using the below tools and frameworks in this post going forward.

  • Visual Studio 2022 with 
  • .NET 6

Step 1: Create a new ASP.NET Core Web API project

Create a new ASP.NET Core Web API project from the available templates.Configuring the AWS SDK for .NET with .NET Core

Provide some additional information such as your project name, project location, etc.Configuring the AWS SDK for .NET with .NET CoreHere, I am using .NET 6 LTS version with controllers option, I have not opted for minimal API. Once you have provided all the information, just press the create button.Configuring the AWS SDK for .NET with .NET Core

Step 2: Install NuGet package

Now, go and install Amazon.Extensions.NETCore.Setup NuGet package.Configuring the AWS SDK for .NET with .NET Core

Step 3: Install AWS Clients for S3 and SQS

In this post, we will configure SDKs for only these 2 services, but this will give you an idea of how to configure them for the rest of the services.

For S3 & SQS, install the below NuGet packages respectively:

Install-Package AWSSDK.S3
Install-Package AWSSDK.SQS
PowerShell

So, by now we have installed below NuGet packages.Configuring the AWS SDK for .NET with .NET Core

Step 4: ASP.NET Core dependency injection

Now, go to Program.cs file and copy the below code there:

// Get the AWS profile information from configuration providers
AWSOptions awsOptions = builder.Configuration.GetAWSOptions();

// Configure AWS service clients to use these credentials
builder.Services.AddDefaultAWSOptions(awsOptions);

// These AWS service clients will be singleton by default
builder.Services.AddAWSService<IAmazonS3>();
builder.Services.AddAWSService<IAmazonSQS>();

This is how over-all Program.cs will look like this:Configuring the AWS SDK for .NET with .NET Core

Step 5: Load AWS credentials in SDK

Go to your appsettings.Development.json file, and provide your local AWS profile information there in the below format.

{
  "AWS": {
    "Profile": "local-test-profile",
    "Region": "us-west-2"
  }
}
JSON

It will look like below:Configuring the AWS SDK for .NET with .NET CoreThis is because in below code snippet, builder.Configuration.GetAWSOptions() populates the AWSOptions.Profile property from an above configuration file.

AWSOptions awsOptions = builder.Configuration.GetAWSOptions();
builder.Services.AddDefaultAWSOptions(awsOptions);

Alternatively, if you don't want to load the credentials from the profile (as that will work only on your local machine), you can also update AWSOptions.Credentials property like below to have the AWS credentials.

AWSOptions awsOptions = new AWSOptions 
{
   Credentials = new BasicAWSCredentials("yourAccessKey", "yourAccessSecret")
};
builder.Services.AddDefaultAWSOptions(awsOptions);

However, even if you don't use both - AWSOptions.Profile and AWSOptions.Crdentials, then also SDK is smart enough to search at certain locations to find the AWS credentials. You can check out this blog to understand how AWS SDK credential loading works.

Step 6: Use S3 & SQS clients in the Controller

To use AWS S3 and SQS clients in the controller, you can write code like the below:

using Amazon.S3;
using Amazon.SQS;
using Microsoft.AspNetCore.Mvc;

namespace AWSSDK.Setup.Demo.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class UserController : ControllerBase
    {
        private readonly IAmazonS3 _s3Client;
        private readonly IAmazonSQS _sqsClient;

        public UserController(IAmazonS3 s3Client, IAmazonSQS sqsClient)
        {
            _s3Client = s3Client;
            _sqsClient = sqsClient;
        }

        [Route("[action]")]
        public async Task TestMethod()
        {
            var s3Response = await _s3Client.ListObjectsAsync("yourBucketName");

            var sqsResponse = await _sqsClient.CreateQueueAsync("yourQuueName");

            return Ok();
        }
    }
}

This is how above code will look like:Configuring the AWS SDK for .NET with .NET CoreThat's all.

Conclusion

In this post, we learned how quickly we can set up AWS SDK in a .NET application for any AWS service that we want to use. Please let me know your thoughts and feedback in the comment section below.


Thank you !!! Happy Learning !!!


Tuesday, May 31, 2022

The operation is not allowed by RBAC. If role assignments were recently changed, please wait several minutes for role assignments to become effective

  Dear Mates, If you are new to key-vault in azure and you are selected Azure role-based access control for more reference pls click this link, If you are facing an issue creating Secret Key solutions are as below 

"The operation is not allowed by RBAC. If role assignments were recently changed, please wait several minutes for role assignments to become effective"

So as per the above error, it is expected we have to assign the role to the User.

Steps:

  1. Go to your Key vault after its created and then click on Access Control (IAM)


  2. Then click on Add Role assignment and then add Key vault Administrator Role to your name:
         

    3. After you review and assign the role, you will be successfully able to create/manage the objects present inside the Key vault.
 



After completing, this process Go to the Secrets option Problem is solved.


Now you can create new 
the Secrets.

Thank you.








Monday, May 30, 2022

Enable Azure RBAC permissions on Key Vault

 Login in azure  Go to Home.



Select Access policies tab from left .


Check Azure role-based access control



Thank , Happy learning 



Wednesday, May 11, 2022

Enable Cross-Origin Requests (CORS) in ASP.NET Core

Hello, All if you are starting working on the .net core I am 100% you are facing the below error at your local.


The solution is very simple you have to add Code in the StartUp or Program file.

var MyAllowSpecificOrigins = "_myAllowSpecificOrigins";

builder.Services.AddCors(options =>

{

    options.AddPolicy(name: MyAllowSpecificOrigins,

                      policy =>

                      {                 

                          policy

                          .AllowCredentials()

                          .SetIsOriginAllowed((host) => true)

                          .AllowAnyHeader()

                          .AllowAnyMethod();

                      });

});

app.UseCors(MyAllowSpecificOrigins);


We have the above code for UI project and Service(Web api) projects.


Thank you !!!

Tuesday, May 10, 2022

The term 'scaffold-dbcontext' is not recognized as the name of a cmdlet, function, script file, or operable program

 Hello All when you want to execute the scaffold-dbcontext "Data Source=(local);Initial Catalog=MyDb;Integrated Security=True;" Microsoft.EntityFrameworkCore.sqlserver -outputdir Models


Gives this error.

scaffold-dbcontext : The term 'scaffold-dbcontext' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At line:1 char:1

+ scaffold-dbcontext "Data Source=(local);Initial Catalog=MyDB;In ...
+ ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (scaffold-dbcontext:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException


Solution:- The solution is as below 

For me apparently, it worked once I have also ran in the Package Manager console :


 Install-Package Microsoft.EntityFrameworkCore.Tools 



Thank you.

 

Monday, May 9, 2022

API Gateway Ocelot .Net Core 6 Setup

 

Add json file called ocelot.json in your project and default configuration are as below 

{

  "ReRoutes": [

    {

      "DownStreamPathTemplate": "api/WeatherForecast",

      "DownStreamScheme": "http",

      "DownStreamHostAndPorts": [

        {

          "Host": "localhost",

          "Post": 7020

        }

      ],

      "UpStreamPathTemplate": "/WeatherForecast",

      "UpStreamHttpMethod": [ "GET" ]

    }

  ]

}



Then do configure like this in Program.cs:


using Ocelot.DependencyInjection;
using Ocelot.Middleware;

IConfiguration configuration = new ConfigurationBuilder()
                            .AddJsonFile("ocelot.json")
                            .Build();

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddOcelot(configuration);

var app = builder.Build();

app.UseOcelot();
app.Run();


Hope it helps you.Happy Learning ! 


Thank you