Install Visual Studio 2017 or Visual Studio 2019 here. Install the AWS Toolkit for Visual Studio. Go to Extensions/Manage Extensions in Visual Studio; Search for AWS Toolkit; Download. The AWS Toolkit for Visual Studio is an extension for Microsoft Visual Studio on Windows that makes it easier for developers to develop, debug, and deploy.NET applications using Amazon Web Services. With the AWS Toolkit for Visual Studio, you'll be able to get started faster. Rating & Review. Note: This edition of the toolkit is for Visual.
The AWS Toolkit for Visual Studio is a plugin (aka Extension) for the Visual Studio IDE that makes it easier for you to develop, debug, and deploy .NET applications that use Amazon Web Services (per AWS Docs).
In this article, we will be setting up the AWS Toolkit for Visual Studio 2019 (any edition), configure the AWS Profile, explore various AWS services via the toolkit, check out different project templates provided as part of the toolkit.
An important pre-requisite is to have an AWS Account created. A free tier is sufficient for exploring and learning the AWS service. Go through the link or any YouTube videos.
- In the upper-right search box, search for AWS and choose Download for the 'AWS Toolkit for Visual Studio 2017 and 2019'. After the toolkit has been installed, open it by choosing AWS Explorer from the View menu.
- The AWS Toolkit supports the use of Visual Studio 2010 and higher. The one caveat to this second requirement is that although Visual Studio Express is supported, its capabilities are very limited. Visual Studio Express does not allow for the use of third-party extensions.
Install the AWS Toolkit extension
You can use any edition of Visual Studio IDE (2017/ 2019/ later) to install the toolkit. Open the Visual Studio — Extensions — Manage Extensions. Please search for the AWS toolkit; it will install once the Visual Studio is closed. The screenshot will give a better idea.
Once it’s installed, you would see AWS Explorer under the View menu.
Setting AWS profile in Visual Studio.
During the AWS account creation, you will create a ROOT account (user) with all the powers for working with your account. AWS recommends not using this ROOT user for daily activities, instead, create a few AWS IAM (Identity and Access Management) users and assigning appropriate permissions to work with AWS service.
Remember, IAM user(s) should have Programmatic access if working with SDKs, CLI or Toolkit.
Login into the AWS console with your AWS Root account, create an IAM user. On opening this IAM user, under the Security Credentials tab, you can create ACCESS KEY to set up the AWS profile in Visual Studio or AWS CLI or any other tools to work with AWS or programmatically work with services.
The screenshot below gives an idea about where the access keys can be generated or refer to this article.Download the CSV file to retain the access keys for future reference.
With the downloaded CSV file from the AWS Explorer, click the Add AWS Credentials Profile (red arrow as shown below) to open the dialog window and enter the following details from the CSV file.
- Access Key Id
- Secret Access Key
- Region – It should match the region AWS account.
The credentials details will be stored in the <home-directory>.awscredentials file; this lets the Visual Studio know the location to pick the details. Remember, we can associate multiple AWS profiles with AWS Explorer and switch as and when needed.
Familiarize with AWS Explorer
Once the profile is set up, the AWS Explorer starts getting loaded with AWS Services that currently part of the AWS Toolkit. You would see CloudFront (CF), EC3, DynamoDB, ECS, S3, SNS, VPC, etc.
We can work with AWS services right from the Visual Studio IDE instead of AWS console web; the changes get reflected vice versa, i.e., any tasks performed in console web are reflected here in AWS Explorer.
The screenshot here shows the AWS Explorer window after I set up the credentials profile. You would see a couple of IAM users created during the account creation process (non-root users).
Create IAM user from AWS Explorer
Navigate to AWS Identity and Access Management (IAM) from the explorer window, expand the Users to see the list of the IAM users for the profile. Right-click on the Users to add a unique username; it would create and show in the list of Users. Quite simple, isn’t it.
The newly created user mithun123 can be edited to add to Groups, generate an access key, and add the policies as shown in the image.
Using the explorer, you can interact with many other services like S3, SNS, Lambda, SNS, etc.
Project Templates from AWS Toolkit
We successfully installed, configured, played with the AWS explorer now. Let’s check out the various project templates added to Visual Studio for .NET development with AWS.
Create a new project from the Visual Studio; you would see the following project templates mainly focused on Serverless and Lambda-related technologies.
If we create AWS Lambda with .NET runtime, we select the appropriate template (as shown above). It presents the blueprint of project templates for AWS Lambda with different pre-written start-up codes for quick development.
What’s Next?
It looks like the .NET development experience and AWS co-exist naturally. In the coming days, let’s explore working with different project templates.
Amazon Web Services is one of the most popular cloud computing platforms on the planet. There’s a good chance you will need to work in an AWS environment, which means publishing to one of their web server services like Elastic Beanstalk. The AWS platform is enormous, and this can be an intimidating task for a developer. Luckily, Amazon has released their AWS Toolkit for Visual Studio 2013-2015 and AWS Toolkit for Visual Studio 2017-2019, which make publishing your web applications to Elastic Beanstalk a snap.
In this article, you will build an ASP.Net MVC web application on .Net 5 using Visual Studio 2019. You will secure this application using Okta. Okta makes it easy to create a secure application with their SSO provider. Once your application is complete you will publish it to a production Elastic Beanstalk instance using the AWS Toolkit.
Table of Contents
What You’ll Need
Write Your MVC Application
Open Visual Studio 2019 and select Create a new project. Under Templates select ASP.Net Core Web Application and give your application a meaningful name. I named mine Okta_AWSToolkit
, and my namespaces in code will reflect that.
Next, press Create then under Create a new ASP.NET Core web application select ASP.NET Core Web App (Model-View-Controller) and ensure that ASP.NET Core 5.0 is selected.
Wait a few moments for Visual Studio to scaffold the project.
Next, you will install the necessary dependencies for the application. In this instance, you will only need the Okta AspNetCore package from NuGet. You can install this with the package command Install-Package Okta.AspNetCore -Version 3.5.0
or by using the package manager interface.
Your application should have a file called appsettings.json
. You will use this as a template for your appsettings files for development and production. Add the following JSON to it.
This file lacks any sensitive information, so you can check this into your source control. You will populate two files shortly: appsettings.Development.json
and appsettings.Production.json
. For now, you can add those files and add the same template as appsettings.json
.
Next, open your HomeController.cs
file and add the following code.
This controller has an Index
action that will be your home page. Under the Index
action you are checking if the user is authenticated. If they are, then you will redirect them to the Profile
page, otherwise, they can continue to the Home page.
Next, create a controller called AccountController.cs
and add the following code.
This controller contains Login
and Logout
actions. There are no views here since Okta will deliver the login page for you. The Login
action should check that the user is not authenticated before returning the ChallengeResult
. The Logout
action redirects the user to the Home page.
Aws Toolkit For Visual Studio 2017
The last controller you need is the Profile
controller. Add a new controller called ProfileController.cs
. The code follows.
The only purpose of this controller is to serve the Profile/Index
page. The Index
action is decorated with the Authorize
attribute, which will automatically send unauthenticated users to the Okta login page.
Next, you can begin to work on your views. The first thing to edit is Layout.cshtml
. Replace the boilerplate code with the following:
Much of this code is the same as the boilerplate, with one major exception. You’ve added a Login
button to the navbar that turns into a Logout
button if the user is authenticated.
Next, open Home/Index.cshtml
and replace the code with the following.
This page provides some additional information about the project and replaces the standard ASP.NET introduction.
Finally, add a new view for Profile/Index.cshtml
and add the following code.
There’s not much going on here, we just present a page for users to understand that they are authenticated and have made it to the profile page. You can edit this page with whatever code you feel fits here.
Finally, you need to edit your Startup.cs
code to enable and configure authentication with Okta. Replace the code in this file with the following.
This file brings it all together. You have registered the Okta component using the appsettings
file that matches your ASPNETCORE_ENVIRONMENT
variable. Now you can easily change your Okta application depending on your environment.
Create your Okta Development Application
You’ll need to create an Okta application for your development environment. You can use the Okta CLI tool. Download the CLI tool and run okta login
. This will walk you through the login process. Once that is completed run okta apps create
and follow the prompts on the screen. Select web as your application type. For your Redirect URI, use the web address provided from your application and append /okta/callback
to it. For your Post Logout RedirectURI, use the same domain. This time, append /signout/callback
to it. If you have multiple authorization servers you can select default for this application. After a moment, the CLI will write your Client Id, Client Secret, and Issuer to a file called .okta.env
in the same directory you were working in. Take these values and add them to your appsettings.Development.json
file.
NOTE: you will only need the Domain portion of your Issuer, not the full URL. You can then delete the contents of .okta.env
.
At this time you can begin your project and ensure everything is working as you expect in development mode.
Set up the Amazon Tool Kit
Now it’s time to publish your application to your Elastic Beanstalk. You should have already installed the AWS Toolkit extension, but go ahead and install it now if you haven’t. The first time it opens, you’ll see a screen with instructions on how to set up the extension.
The screen will instruct you to log into the IAM Users page in the AWS console and create a user. Click on that link and set up a new user.
Create the new user, then attach an administrator or power user policy to the user. Next, you will be presented with the Access Key and Secret Key. Copy and paste those into the AWS Toolkit, then press save, and close.
Publish to AWS Elastic Beanstalk
Visual Studio Code
Next, right-click on your project and click Publish to AWS Elastic Beanstalk. This will open a new wizard to guide you through the publish process.
First is the application tab. Select Create a new application environment and then select Next.
Under the Application Environment screen select the production version of your environment. This action will automatically populate the URL for your Elastic Beanstalk instance. You’ll want to check to make sure the URL is available before moving forward.
Under the Options tab, the only change you need to make is to use a t2.micro instance to maintain your free tier status. If you need to scale up later Amazon makes that easy through the AWS Toolkit.
Under the options tab you will want to select the Release configuration.
Finally, on the view tab, click Deploy and wait a few minutes for the site to be published and the server to be live. You will receive a notification when it is ready. From there, you can click the link to your site to see the published version. However, at this time, you will notice your login screen doesn’t work as expected. This is because you still need to populate your production Okta credentials.
Create Your Okta Production Application
Open your CLI again and go through the okta apps create
wizard. However this time, instead of using the localhost
domain provided by Visual Studio, replace the domain in your Redirect URI and Post Logout RedirectURI with the domain at which AWS published your application. After a moment, the CLI will again write your details to .okta.env
and you can replace your appsettings.Production.json
values with these new ones. Again, only use the domain of your Issuer in the domain field of your appsettings file.
Aws Toolkit For Visual Studio 2017 Free
You will need to publish your application to AWS one last time to ensure that the updated appsettings.Production.json
reaches the server. Once that is complete you should be able to log in to your application again.
Conclusion
The AWS Toolkit is a powerful tool that helps you integrate with AWS Cloud services easily from Visual Studio. This article is a brief introduction to the capabilities of the tool. If you use AWS for development, I recommend exploring all the features of the AWS Toolkit for Visual Studio.
Check out the code from this tutorial in this GitHub repo.
Learn More About C# and AWS
Make sure you follow us on Twitter and subscribe to our YouTube channel. If you have any questions, or you want to share what tutorial you’d like to see next, please comment below.