Step 1: Get an access key and secret key for your IAM user Step 2: Install AWS Toolkit for Visual Studio and connect to CodeCommit Clone a CodeCommit repository from Visual Studio Create a CodeCommit repository from Visual Studio Working with CodeCommit repositories. HOW TO CONNECT TO AWS INSTANCE (EC2) Open Visual Studio Code and install extension - 'Remote - SSH' After installation click the green link icon bottom left of the VSC to 'Open a remote window' Select 'Remote-SSH: Connection to host. The AWS Toolkit for Visual Studio Code provides support for AWS Lambda functions. Using the Toolkit for VS Code, you can author code for Lambda functions that are part of serverless applications. In addition, you can invoke Lambda functions either locally or on AWS. Lambda is a fully managed compute service that runs your code in response to events generated by custom code or from various AWS.
A quick post for working on AWS using Visual Studio Code and terraform.
Install Terraform
Download the latest terraform software and install it on your machine. For windows, keep terraform.exe
downloaded from this page in C:WindowsSystem32
and that should be enough.
Install Visual Studio Code
Download Microsoft Visual Studio Code software from their website. Install and launch Visual Studio Code. It supports many code languages. But many of them are not supported on install. One needs to add extensions from the extension marketplace to make it available in VSC.
Install Terraform Visual Studio Code extension
The official Visual Studio Code extension for Terraform is HashiCorp Terraform. You can visit this link and click on the Install button on the webpage, which in turn opens up VSC and install the extension or follow the below procedure.
- Launch Visual Studio Code
- Click on the Extensions shortcut on the left navigation panel.
- Search terraform in extensions marketplace
- Select HashiCorp Terraform from search results
- Click the Install button.
Once installed it will be available to use.
Login to AWS account for terraform
It’s programmatic access you will be configuring to AWS. So for that, you should create Access keys through the IAM AWS console. Once you are ready with a valid AWS account with programmatic access enabled and downloaded its access keys, head back to VSC.
Create a new file main.tf
with the below code for login. Make sure you use your own key values in there :
and in terminal below, run terraform init
command.
Although hard coding credentials like this is not recommended, you can define them as environment variables or other methods supported by terraform.
This should initialize Terraform to use with AWS. It will download the AWS plugin for Terraform. Sample output –
The next step is scanning existing AWS infra to give an account to make the terraform aware of it. Execute the terraform plan
command. This command now will use the access keys defined in the file, login to AWS, and check the existing infra.
Creating sample user in AWS using terraform from Visual Studio Code
Now to test a small command, let’s define a user in the file. If that user existing in your AWS account, you should see the same output as above. If not, terraform should show that a new user needs to be created to match the file’s requirements.
Ensure the user you are using in terraform has permissions to create resources in AWS you are planning to.
Add below code in file, save and run terrafrom plan
again.
As you can see, since testuser
is not existing in AWS infra, it’s prompting to create one! To apply the changes, run the terraform apply
command, and it will execute the operation.
Finally, to verify the user created run terrafrom show
command.
Finally, to delete all resources being created by terraform, you can run terrafrom destroy
command.
It should ask confirmation and then proceed with deleting resources.
AWS Elastic Beanstalk
Use the AWS Toolkit for Visual Studio to develop, debug, then deploy your .NET web applications using a web application template. Use Visual Studio to build and run your application locally before deploying to AWS Elastic Beanstalk. Learn more »
Visual Studio Aws Lambda Project
AWS Lambda and Amazon API Gateway
Create serverless applications with minimal administration and event-driven scaling with C# and Node.js using AWS Lambda and Amazon API Gateway.
Amazon Elastic Container Service
Easily build, register and deploy .NET Core Docker applications to the Amazon Elastic Container Service without ever leaving Visual Studio. Learn More »
AWS Explorer
The AWS Explorer lets you manage your AWS resources. Including your Amazon S3 Objects, Amazon DynamoDB Tables and EC2 instances.
CloudFormation Editor
Create new .NET web applications using an application template. Use Visual Studio to build with the convenience of IntelliSense and deploy to AWS with AWS CloudFormation. Learn more »
Visual Studio Code Aws Sam
Project Templates
The AWS Toolkit for Visual Studio includes project templates for AWS Lambda functions, AWS CloudFormation templates and sample projects showing how to use various AWS services.