AWS Toolkit For VS Code: User Guide

Download as pdf or txt
Download as pdf or txt
You are on page 1of 34

AWS Toolkit for VS Code

User Guide
AWS Toolkit for VS Code User Guide

AWS Toolkit for VS Code: User Guide


Copyright © 2019 Amazon Web Services, Inc. and/or its affiliates. All rights reserved.

Amazon's trademarks and trade dress may not be used in connection with any product or service that is not
Amazon's, in any manner that is likely to cause confusion among customers, or in any manner that disparages or
discredits Amazon. All other trademarks not owned by Amazon are the property of their respective owners, who may
or may not be affiliated with, connected to, or sponsored by Amazon.
AWS Toolkit for VS Code User Guide

Table of Contents
AWS Toolkit for Visual Studio Code ...................................................................................................... 1
What is the AWS Toolkit for Visual Studio Code ............................................................................. 1
Related Information ................................................................................................................... 1
Setting Up ........................................................................................................................................ 2
Installing the Toolkit for VS Code ................................................................................................ 2
Prerequisites ...................................................................................................................... 2
Install the Toolkit for VS Code ............................................................................................. 3
Establishing Credentials .............................................................................................................. 3
Using AWS-Supported Credentials ........................................................................................ 4
Using an External Credential Process .................................................................................... 7
Connecting to AWS .................................................................................................................... 8
Connect to AWS through the Toolkit for VS Code ................................................................... 8
Use Multiple AWS Accounts with the Toolkit ........................................................................ 10
Changing AWS Regions ............................................................................................................. 10
Add a Region to the AWS Explorer ..................................................................................... 10
Hide a Region from the AWS Explorer ................................................................................. 12
Configuring Your Toolchain ....................................................................................................... 13
Configure a Toolchain for .NET Core ................................................................................... 13
Configure a Toolchain for Node.js ....................................................................................... 13
Configure a Toolchain for Python ....................................................................................... 13
Using Your Toolchain ........................................................................................................ 14
Navigating the Toolkit for VS Code .................................................................................................... 15
Fundamental UI Components ..................................................................................................... 15
Command Locations ................................................................................................................. 15
Visual Studio Code Command Palette ................................................................................. 16
AWS Explorer Menu ......................................................................................................... 17
Working with AWS Services ............................................................................................................... 18
AWS Serverless Applications ...................................................................................................... 19
Creating a Serverless Application ....................................................................................... 19
Deploying a Serverless Application ..................................................................................... 23
AWS Lambda Functions ............................................................................................................. 25
Interacting with Remote Lambda Functions ......................................................................... 25
AWS CloudFormation Stacks ...................................................................................................... 28
Deleting an AWS CloudFormation Stack .............................................................................. 28
Amazon ECS ............................................................................................................................ 29
Using IntelliSense for Task Definition Files ........................................................................... 29
Document History ............................................................................................................................ 31

iii
AWS Toolkit for VS Code User Guide
What is the AWS Toolkit for Visual Studio Code

AWS Toolkit for Visual Studio Code


This is the user guide for the AWS Toolkit for VS Code. If you are looking for the AWS Toolkit for Visual
Studio, see the User Guide for the AWS Toolkit for Visual Studio.

What is the AWS Toolkit for Visual Studio Code


The Toolkit for VS Code is an open-source extension for the Visual Studio Code (VS Code) editor. This
extension makes it easier for developers to develop, debug locally, and deploy serverless applications
that use Amazon Web Services (AWS).

Topics

• Setting Up the AWS Toolkit for Visual Studio Code (p. 2)


• Navigating the AWS Toolkit for Visual Studio Code (p. 15)
• Working with AWS Services (p. 18)

Related Information
Use the following resources to access the source code for the toolkit or view currently open issues.

• Source Code
• Issue Tracker

To learn more about the Visual Studio Code editor, visit https://code.visualstudio.com/.

1
AWS Toolkit for VS Code User Guide
Installing the Toolkit for VS Code

Setting Up the AWS Toolkit for


Visual Studio Code
This section helps you set up the AWS Toolkit for Visual Studio Code. It provides information about how
to install and configure the toolkit, set up your credentials, and connect to AWS.

Topics
• Installing the AWS Toolkit for Visual Studio Code (p. 2)
• Establishing Credentials for the AWS Toolkit for Visual Studio Code (p. 3)
• Connecting to AWS through the AWS Toolkit for Visual Studio Code (p. 8)
• Changing AWS Regions (p. 10)
• Configuring Your Toolchain (p. 13)

Installing the AWS Toolkit for Visual Studio Code


This section describes how to install the AWS Toolkit for Visual Studio Code.

Prerequisites
Required
Before you can install the Toolkit for VS Code, you must have the following:

• An Amazon Web Services account – To obtain an AWS account, go to the AWS home page. Choose
Create an AWS Account, or Complete Sign Up (if you've visited the site before). Signing up enables
you to use all of the services that AWS offers.
• A supported operating system – The Toolkit for VS Code is supported on Windows, Linux, and macOS.
• The relevant SDK for the language that you want to use. You can download from the following links,
or use your favorite package manager:
• .NET SDK: https://dotnet.microsoft.com/download
• Node.js SDK: https://nodejs.org/en/download
• Python SDK: https://www.python.org/downloads
• VS Code version 1.31.1 or later – We try to keep the Toolkit for VS Code current with the default
version that's available on the VS Code download page.

Optional
Before you can use certain features of the Toolkit for VS Code, you must have the following:

• AWS SAM CLI – This is an AWS CLI tool that helps you develop, test, and analyze your serverless
applications locally. This isn't required for installing the toolkit. However, we recommend that you
install it (and Docker, described next) because it's required for any AWS Serverless Application Model
(AWS SAM) functionality, such as Creating a Serverless Application (p. 19).

For more information, see Installing the AWS SAM CLI in the AWS Serverless Application Model
Developer Guide.

2
AWS Toolkit for VS Code User Guide
Install the Toolkit for VS Code

• Docker – The AWS SAM CLI requires this open-source software container platform. For more
information and download instructions, see Docker.

Install the Toolkit for VS Code


1. Start the VS Code editor.
2. In the Activity Bar on the side of the VS Code editor, choose the Extensions icon. This opens the
Extensions view, which allows you to access the VS Code Marketplace.

3. In the search box for Extensions, search for AWS Toolkit for Visual Studio Code. Choose the entry
to see its details in the right pane.
4. In the right pane, choose Install.
5. Once installed, if you're prompted to restart the editor, choose Reload Required to finish
installation.

After you install the Toolkit for VS Code, you should configure your credentials (p. 3) to enable you
to access your AWS resources from within VS Code.

Establishing Credentials for the AWS Toolkit for


Visual Studio Code
This section shows you the types of credentials that you can use with the AWS Toolkit for VS Code. It
provides information about how to get and configure those credentials.

You can obtain credentials through AWS and provide them to the toolkit by using configuration files. You
can also obtain credentials through an external credential process that isn't directly supported by AWS.

3
AWS Toolkit for VS Code User Guide
Using AWS-Supported Credentials

Topics
• Using AWS-Supported Credentials (p. 4)
• Using an External Credential Process (p. 7)

Using AWS-Supported Credentials


AWS credentials can be provided to the AWS Toolkit for VS Code by using your shared AWS config file or
your shared AWS credentials file. The methods for using these files are the same as those for the AWS CLI.
For general information about how to use these files, see Configuration and Credential Files in the AWS
Command Line Interface User Guide.

Topics
• Obtaining AWS Access Keys (p. 4)
• Setting Up Your AWS Credentials (p. 5)

Obtaining AWS Access Keys


To access Amazon Web Services (AWS) with the AWS Toolkit for Visual Studio Code, you must configure
the toolkit with AWS account credentials. To do this with AWS-supported credentials, you must first
obtain appropriate AWS access keys.

For more information about users and credentials that is out of scope for this guide, see the following
resources:

• AWS Security Credentials in the Amazon Web Services General Reference


• Overview of Identity Management: Users in the IAM User Guide

What are AWS Access Keys


Access keys are the credentials that identify you to AWS and enable you to programmatically access AWS
services and resources. Access keys can be associated with your AWS account (the account's "root user")
or with users that you create with AWS Identity and Access Management (IAM).
Warning
Because the root user is essentially an administrator with full access to services and resources,
we recommend that you instead create an IAM user with only those permissions needed
to perform the required tasks. Then, for your credentials, you can use an access key that is
associated with that user. For details, see Creating an IAM User in Your AWS Account in the IAM
User Guide.

An access key consists of an access key ID, which is similar to a user name, and a secret access key, which
is similar to a password. This access key is used to sign programmatic requests that you make to AWS. If
you don't have access keys, you can create them by using the AWS Management Console. We recommend
that you use access keys for an IAM user instead of the keys for your account's root user.
Note
To create access keys, you must have permissions to perform the required IAM actions. For more
information, see Granting IAM User Permissions to Manage Password Policy and Credentials in
the IAM User Guide.

Get Your AWS Access Keys


1. Open the IAM console at https://console.aws.amazon.com/iam/.
2. On the navigation menu, choose Users.

4
AWS Toolkit for VS Code User Guide
Using AWS-Supported Credentials

3. Choose your IAM user name (not the check box) to view its details.
4. On the Security Credentials tab, choose Create access key.
5. To see the new access key, choose Show. The credentials resemble the following:

• Access key ID: AKIAIOSFODNN7EXAMPLE


• Secret access key: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
6. To download the key pair, choose Download .csv file. Store the keys in a secure location.
Important

• Keep the keys confidential to protect your AWS account, and never email them. Do not
share them outside of your organization, even if an inquiry appears to come from AWS or
Amazon.com. No one who legitimately represents Amazon will ever ask you for your secret
key.
• You can't recover the secret key if you lose it. Instead, for security reasons, you must
create a new key pair and delete the old pair.

After you have obtained your AWS access keys, you can use the AWS Toolkit for VS Code to store them in
your shared AWS config file or your shared AWS credentials file. See Add Your AWS Access Keys to Your
Environment (p. 5) to learn how.

Setting Up Your AWS Credentials


To access Amazon Web Services (AWS) with the AWS Toolkit for Visual Studio Code, you must make your
AWS account credentials available to the toolkit. To use AWS-supported credentials, continue reading in
this topic. To use an external credential process, see Using an External Credential Process (p. 7).
Note
Some features of the Toolkit for VS Code, such as creating a serverless application, don't require
AWS credentials.

Get Your AWS Access Keys


If you don't already have appropriate AWS access keys to store in your shared AWS config file or your
shared AWS credentials file, you must get them now.

To do so, see Obtaining AWS Access Keys (p. 4).

About Shared AWS Files


Your shared AWS config file and your shared AWS credentials file are files that you can use to store
configuration and credential information for AWS. By default, these files are located in the .aws
directory within your home directory and are named config and credentials, respectively. For more
information, see Where Are Configuration Settings Stored? in the AWS Command Line Interface User
Guide.

The Toolkit for VS Code locates and uses AWS access keys through your shared AWS config file and your
shared AWS credentials file. This is the method that is used by the AWS CLI and the AWS SDKs. Access
keys that you enter in the Toolkit for VS Code are saved to one of these files.

These shared files can contain the credentials for more than one AWS account, stored as profiles. Multiple
accounts can be useful, for example, to provide developers and administrators with separate resources
for development and for release or publication.

Add Your AWS Access Keys to Your Environment


If you have already set your AWS credentials (for example, by using the AWS CLI), the Toolkit for VS Code
will automatically detect those credentials and make them available to the toolkit. If you haven't already

5
AWS Toolkit for VS Code User Guide
Using AWS-Supported Credentials

set your AWS credentials, or if you want to include additional AWS credentials in your environment or
update an existing credentials profile, you can do so through the Toolkit for VS Code, as shown here.
Note
As an alternative to these procedures, you can use the aws configure AWS CLI command to add
AWS credentials to your environment. You can also use aws configure to set the default AWS
Region, which is needed for certain operations such as creating a serverless application.

Create the Shared AWS Credentials File

• If you already have a shared AWS credentials file, you can skip to the next procedure (p. 7).
• If you already have a shared AWS config file and want to use it, you can skip to the next
procedure (p. 7).
• If you have only a shared AWS config file but do NOT want to use it, you must first create a shared AWS
credentials file by using techniques that are normal for your operating-system. After that, you can skip
to the next procedure (p. 7).

Follow these steps to create the shared AWS credentials file.

1. Open VS Code.
2. To open the Command Palette, on the menu bar, choose View, Command Palette. Or use the
following shortcut keys:

• Windows and Linux – Press Ctrl+Shift+P.


• macOS – Press Shift+Command+P.
3. Search for AWS and choose AWS: Create Credentials Profile.

4. Enter a name for the initial profile.

5. Enter the access key ID for the credentials. If you don't have an access key ID, see Obtaining AWS
Access Keys (p. 4).

6. Enter the secret access key for the credentials. If you don't have a secret access key, see Obtaining
AWS Access Keys (p. 4).

6
AWS Toolkit for VS Code User Guide
Using an External Credential Process

After you complete this procedure, you can verify the shared AWS credentials file by opening it directly
or by performing the first three steps of the next procedure (without making any updates).

Update one of Your Shared Files

Follow these steps to add a new profile to your existing shared AWS config file or shared AWS credentials
file. You can also update an existing profile.

1. Open VS Code.
2. To open the Command Palette, on the menu bar, choose View, Command Palette. Or use the
following shortcut keys:

• Windows and Linux – Press Ctrl+Shift+P.


• macOS – Press Shift+Command+P.
3. Search for AWS and choose AWS: Create Credentials Profile.

4. When one or both of the shared files opens in the VS Code editor, add or update a profile.
5. When you're finished updating the file, save it.

Using an External Credential Process


If you have a process to generate or lookup credentials that isn't directly supported by AWS,
you can configure the AWS Toolkit for VS Code to use that process instead of any stored AWS
credentials (p. 4).

The method for specifying such an external credential process is the same as for the AWS CLI, and
consists of adding a credential_process definition to your shared AWS config file. For detailed
information about how to do this, see Sourcing Credentials with an External Process in the AWS
Command Line Interface User Guide.

7
AWS Toolkit for VS Code User Guide
Connecting to AWS

Connecting to AWS through the AWS Toolkit for


Visual Studio Code
To interact with Amazon Web Services (AWS) through the AWS Toolkit for Visual Studio Code, you must
establish a connection to AWS.

Connect to AWS through the Toolkit for VS Code


1. Open VS Code.
2. To open the Command Palette, on the menu bar, choose View, Command Palette. Or use the
following shortcut keys:

• Windows and Linux – Press Ctrl+Shift+P.


• macOS – Press Shift+Command+P.
3. Search for AWS and choose AWS: Connect to AWS.

4. Choose a profile from the list.

If you don't have a credentials profile set up, you are prompted to set one up. Look for a pop-up
in the lower-right corner of the editor. Choose Yes, and then follow the setup wizard to enter a
profile name, your access key ID, and your secret access key. For details, see Setting Up Your AWS
Credentials (p. 5).
Note
If you want to provide an external credential process instead of using AWS-supported
credentials, choose No and see Using an External Credential Process (p. 7) instead.

8
AWS Toolkit for VS Code User Guide
Connect to AWS through the Toolkit for VS Code

5. Open the AWS: Explorer Side Bar, which we call the AWS Explorer, to verify the connection. You
will see either a list of AWS Regions (if you have made any Regions visible (p. 10) in the AWS
Explorer) or a message to add Regions to the AWS Explorer.

Before adding Regions (p. 10) to the AWS Explorer, you see the following.

After adding Regions to the AWS Explorer, you see something like the following.

9
AWS Toolkit for VS Code User Guide
Use Multiple AWS Accounts with the Toolkit

Use Multiple AWS Accounts with the Toolkit


You might have multiple AWS accounts that you want to access from the Toolkit for VS Code. Multiple
accounts can be useful, for example, to provide developers and administrators with separate resources
for development and for release or publication.

Separate sets of AWS credentials are stored as profiles within the shared AWS config file or the shared
AWS credentials file. To choose a different set of credentials, follow the steps in the previous procedure,
and choose a different profile.

Changing AWS Regions


When you set up your credentials, the AWS Toolkit for Visual Studio Code automatically selects and
shows the default AWS Region for those credentials in the AWS Explorer. This topic describes how to
change the list of Regions that is shown in the AWS Explorer.

Add a Region to the AWS Explorer


1. To open the Command Palette, on the menu bar, choose View, Command Palette. Or use the
following shortcut keys:

• Windows and Linux – Press Ctrl+Shift+P.


• macOS – Press Shift+Command+P.
2. Search for AWS and choose AWS: Show Region in the Explorer.

10
AWS Toolkit for VS Code User Guide
Add a Region to the AWS Explorer

3. Choose the Region that you want to add to the AWS Explorer.

Note
The list contains only those Regions that are available to add to the AWS Explorer. Regions
you've already added don't appear in the list.
4. Verify that the Region now appears in the AWS Explorer.

11
AWS Toolkit for VS Code User Guide
Hide a Region from the AWS Explorer

Hide a Region from the AWS Explorer


1. Choose the AWS icon in the Activity bar to open the AWS Explorer.
2. Choose one of the Regions in the list, and open its context menu.

12
AWS Toolkit for VS Code User Guide
Configuring Your Toolchain

3. Choose Hide Region from the Explorer.

Configuring Your Toolchain


The AWS Toolkit for Visual Studio Code supports multiple languages that you can use to interact with
AWS. This topic describes how to set up the toolchain for each of these languages.

Configure a Toolchain for .NET Core


1. Ensure that you have the Toolkit for VS Code installed (p. 3).
2. Install the C# extension. This extension enables VS Code to debug .NET Core applications.
3. Open an AWS Serverless Application Model (AWS SAM) application, or create one (p. 19).
4. Open the folder that contains template.yaml.

Configure a Toolchain for Node.js


1. Ensure that you have the Toolkit for VS Code installed (p. 3).
2. Open an AWS SAM application, or create one (p. 19).
3. Open the folder that contains template.yaml.

Configure a Toolchain for Python


1. Ensure that you have the Toolkit for VS Code installed (p. 3).
2. Install the Python extension for Visual Studio Code. This extension enables VS Code to debug
Python applications.
3. Open an AWS SAM application, or create one (p. 19).

13
AWS Toolkit for VS Code User Guide
Using Your Toolchain

4. Open the folder that contains template.yaml.


5. Open a terminal at the root of your application, and configure virtualenv by running python -m
venv ./.venv.
Note
You only need to configure virtualenv once per system.
6. Activate virtualenv by running one of the following:

• Bash shell: ./.venv/Scripts/activate


• PowerShell: ./.venv/Scripts/Activate.ps1

Using Your Toolchain


Once you have your toolchain set up, you can use it to run or debug (p. 21) the AWS SAM application.

14
AWS Toolkit for VS Code User Guide
Fundamental UI Components

Navigating the AWS Toolkit for


Visual Studio Code
This topic describes how to navigate in the AWS Toolkit for Visual Studio Code. Be sure to first install the
toolkit (p. 2) before reading this topic.

For general information about the Visual Studio Code user interface (UI), see the UI documentation for
VS Code.

Fundamental UI Components
The following are the basic UI components of the AWS Toolkit for VS Code.

The UI element named AWS Explorer is more formally known as the AWS: Explorer Side Bar.

Command Locations
You can find the commands for the Toolkit for VS Code in various locations.

15
AWS Toolkit for VS Code User Guide
Visual Studio Code Command Palette

Visual Studio Code Command Palette


The VS Code Command Palette contains all the commands you can use for working with AWS services.
To see these commands, open the VS Code Command Palette from the View menu. Or use the following
shortcuts:

• Windows and Linux – Press Ctrl+Shift+P.


• macOS – Press Shift+Command+P.

Then you can filter for "AWS".

16
AWS Toolkit for VS Code User Guide
AWS Explorer Menu

AWS Explorer Menu


The AWS Explorer has a More Actions menu that contains the most common commands for working
with AWS services.

17
AWS Toolkit for VS Code User Guide

Working with AWS Services


The AWS Explorer gives you a view of the AWS services that you can work with when using the AWS
Toolkit for Visual Studio Code. This section provides information about how to access and use the AWS
Explorer in VS Code. It assumes that you've already installed and configured (p. 2) the Toolkit for VS
Code on your system.

Some important points:

• If the toolkit is installed and configured correctly, you should see items in the AWS Explorer. To see
the AWS Explorer, choose the AWS icon in the Activity bar.

For example:

• Certain features require certain AWS permissions. For example, to see the AWS Lambda functions
in your AWS account, the credentials you configured in Establishing Credentials (p. 3) must include
at least read-only Lambda permissions. See the following topics for more information about the
permissions that each feature needs.

Topics
• Working with AWS Serverless Applications (p. 19)

18
AWS Toolkit for VS Code User Guide
AWS Serverless Applications

• Working with AWS Lambda Functions (p. 25)


• Working with AWS CloudFormation Stacks (p. 28)
• Working with Amazon Elastic Container Service (p. 29)

Working with AWS Serverless Applications


The AWS Toolkit for Visual Studio Code provides support for serverless applications. Using the Toolkit for
VS Code, you can create serverless applications that contain AWS Lambda functions, and then deploy the
applications to an AWS CloudFormation stack.

Topics
• Creating a Serverless Application with the AWS Toolkit for Visual Studio Code (p. 19)
• Deploying a Serverless Application with the AWS Toolkit for Visual Studio Code (p. 23)

Creating a Serverless Application with the AWS


Toolkit for Visual Studio Code
This example shows how to use the AWS Toolkit for Visual Studio Code to create a serverless application
and then run and debug it.

Prerequisites
• If you haven't already done so, satisfy the required prerequisites specified in Installing the Toolkit for
VS Code (p. 2).
• In addition, install the AWS SAM CLI and its prerequisites. See AWS SAM CLI in the setup
prerequisites (p. 2). If Visual Studio Code is open when you perform these installations, you might need
to close and reopen the editor.
• Identify your default AWS Region in your AWS config file. For more information, see Configuration and
Credential Files in the AWS CLI User Guide. If Visual Studio Code is open when you update your config
file, you might need to close and reopen the editor.
• After installing your language SDK, be sure to configure your toolchain (p. 13).

Create a Serverless Application with the Toolkit for VS Code


This example shows how to create a serverless application with the Toolkit for VS Code by using the AWS
Serverless Application Model (AWS SAM).

1. To open the Command Palette, choose View, Command Palette, and then enter AWS.
2. Choose AWS: Create new SAM Application.

Note
If the AWS SAM CLI isn't installed, you will get an error in the lower-right corner of the VS
Code editor. If this happens, see the prerequisites (p. 19) described earlier.
3. Choose the runtime for your SAM application. For this example, choose nodejs10.x.

19
AWS Toolkit for VS Code User Guide
Creating a Serverless Application

4. Choose a location for your new project. You can use an existing workspace folder if one is open,
Select a different folder that already exists, or create a new folder and select it. For this example,
choose There are no workspace folders open to create a folder named MY-SAM-APP.

5. Enter a name for your new project. For this example, use my-sam-app-nodejs. After you press
Enter, the Toolkit for VS Code takes a few moments to create the project.

When the project is created, your application is added to your current workspace. You should see it listed
in the Explorer window.

20
AWS Toolkit for VS Code User Guide
Creating a Serverless Application

Run and Debug Your Serverless Application


After the AWS SAM application is created, you can use CodeLens indicators to run and debug the
application.

1. From the hello-world directory in the project explorer, open app.js, if it isn't already open.

21
AWS Toolkit for VS Code User Guide
Creating a Serverless Application

2. Select the Run Locally CodeLens indicator.


Note
To supply event information, select the Configure indicator from the CodeLens line in your
code, as shown.

If CodeLens indicators aren't visible, select the AWS Explorer icon in the Activity Bar to activate
CodeLens.

22
AWS Toolkit for VS Code User Guide
Deploying a Serverless Application

3. After the local run is complete, the output appears on the OUTPUT tab or the TERMINAL tab.

Note
For Windows users, if you encounter a Docker mounting error during this process, you
might need to refresh the credentials for your shared drives (in Docker Settings). A Docker
mounting error might look something like the following.

Fetching lambci/lambda:nodejs10.x Docker container image......


2019-07-12 13:36:58 Mounting C:\Users\<username>\AppData\Local\Temp\ ... as /
var/task:ro,delegated inside runtime container
Traceback (most recent call last):
...
requests.exceptions.HTTPError: 500 Server Error: Internal Server Error ...

4. Choose the Debug Locally CodeLens indicator to debug your application. When in debug mode, you
can set breakpoints, step through each line, inspect variables, and change values just as you would
for any application.

Deploying a Serverless Application with the AWS


Toolkit for Visual Studio Code
This example shows how to deploy the serverless application that was created in the previous topic
(Creating a Serverless Application (p. 19)) to AWS using the AWS Toolkit for Visual Studio Code.

Prerequisites
• If you haven't already done so, satisfy the prerequisites specified in Installing the Toolkit for VS
Code (p. 2).
• Be sure to choose a globally unique Amazon S3 bucket name.
• Ensure that the credentials you configured in Establishing Credentials (p. 3) include the appropriate
read/write access to the following services: Amazon S3, AWS CloudFormation, AWS Lambda, and
Amazon API Gateway.

Deploy a Serverless Application


1. To open the Command Palette, choose View, Command Palette, and then enter AWS.

23
AWS Toolkit for VS Code User Guide
Deploying a Serverless Application

2. Choose AWS: Deploy SAM Application.

3. Choose the template.yaml file to use for the deployment.

4. Choose the AWS Region to deploy to.

5. Enter the name of an Amazon S3 bucket this deployment can use. The bucket must be in the Region
you're deploying to.
Warning
The Amazon S3 bucket name must be globally unique across all existing bucket names
in Amazon S3. Therefore, you should add a unique identifier to the name given in the
following example (or choose a different name).

6. Enter a name for the deployed stack, either a new stack name or an existing stack name.

7. Verify the success of the deployment on the OUTPUT tab of VS Code.

24
AWS Toolkit for VS Code User Guide
AWS Lambda Functions

If an error occurs, a message pops up in the lower-right that is similar to the following:

If this happens, check the text in the OUTPUT tab for details. The following is an example of error
details.

Error with child process: Unable to upload artifact HelloWorldFunction referenced by


CodeUri parameter of HelloWorldFunction resource.
S3 Bucket does not exist. Execute the command to create a new bucket
aws s3 mb s3://pbart-my-sam-app-bucket
An error occurred while deploying a SAM Application. Check the logs for more
information by running the "View AWS Toolkit Logs" command from the Command Palette.

In this example, the error occurred because the Amazon S3 bucket did not exist.

When the deployment is complete, you'll see your application listed in the AWS Explorer. To learn how
to invoke the Lambda function that was created as part of the application, see Interacting with Remote
Lambda Functions (p. 25).

Working with AWS Lambda Functions


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 services, such as Amazon Simple Storage Service (Amazon S3),
Amazon DynamoDB, Amazon Kinesis, Amazon Simple Notification Service (Amazon SNS), and Amazon
Cognito.

Topics
• Interacting with Remote Lambda Functions (p. 25)

Interacting with Remote Lambda Functions


Using the Toolkit for VS Code, you can interact with AWS Lambda functions in various ways, as described
later in this topic.

For more information about Lambda, see the AWS Lambda Developer Guide.

25
AWS Toolkit for VS Code User Guide
Interacting with Remote Lambda Functions

Note
If you have already created Lambda functions by using the AWS Management Console or in
some other way, you can invoke them from the Toolkit. To create a new function (using VS Code)
that you can deploy to AWS Lambda, you must first create a serverless application (p. 19).

Prerequisites
• If you haven't already done so, satisfy the prerequisites specified in Installing the Toolkit for VS
Code (p. 2).
• Ensure that the credentials you configured in Establishing Credentials (p. 3) include appropriate read/
write access to the AWS Lambda service. If in the AWS Explorer, under Lambda, you see a message
similar to "Error loading Lambda resources", check the permissions attached to those credentials.
Changes that you make to permissions will take a few minutes to affect the AWS Explorer in VS Code.

Invoke a Lambda Function


You can invoke a Lambda function on AWS from the Toolkit for VS Code.

1. In the AWS Explorer, choose the name of the Lambda function you want to invoke, and then open
its context menu.

2. Choose Invoke on AWS.


3. In the invoke window that opens, enter the input that your Lambda function needs. The Lambda
function might, for example, require a string as an input, as shown in the text box.

26
AWS Toolkit for VS Code User Guide
Interacting with Remote Lambda Functions

You'll see the output of the Lambda function just like you would for any other project using VS Code.

Delete a Lambda Function


You can also delete a Lambda function using the same context menu.
Warning
Do not use this procedure to delete Lambda functions that are associated with AWS
CloudFormation (for example, the Lambda function that was created when creating a serverless
application (p. 19) earlier in this guide). These functions must be deleted through the AWS
CloudFormation stack.

27
AWS Toolkit for VS Code User Guide
AWS CloudFormation Stacks

1. In the AWS Explorer, choose the name of the Lambda function you want to delete, and then open
its context menu.

2. Choose Delete.
3. In the message that appears, choose Yes to confirm the delete.

After the function is deleted, it's no longer listed in the AWS Explorer.

Working with AWS CloudFormation Stacks


The AWS Toolkit for Visual Studio Code provides support for AWS CloudFormation stacks. Using the
Toolkit for VS Code, you can perform certain tasks with AWS CloudFormation stacks, such as deleting
them.

Topics
• Deleting an AWS CloudFormation Stack (p. 28)

Deleting an AWS CloudFormation Stack


You can use the AWS Toolkit for Visual Studio Code to delete AWS CloudFormation stacks.

28
AWS Toolkit for VS Code User Guide
Amazon ECS

Prerequisites
• If you haven't already done so, satisfy the prerequisites specified in Installing the Toolkit for VS
Code (p. 2).
• Ensure that the credentials you configured in Establishing Credentials (p. 3) include appropriate read/
write access to the AWS CloudFormation service. If in the AWS Explorer, under CloudFormation, you
see a message similar to "Error loading CloudFormation resources", check the permissions attached to
those credentials. Changes that you make to permissions will take a few minutes to affect the AWS
Explorer in VS Code.

Delete a CloudFormation Stack

1. In the AWS Explorer, open the context menu of the AWS CloudFormation stack you want to delete.

2. Choose Delete CloudFormation Stack.


3. In the message that appears, choose Yes to confirm the delete.

After the stack is deleted, it's no longer listed in the AWS Explorer.

Working with Amazon Elastic Container Service


The AWS Toolkit for Visual Studio Code provides some support for Amazon Elastic Container Service
(Amazon ECS). The Toolkit for VS Code assists you in certain Amazon ECS-related work, such as creating
task definitions.

Topics
• Using IntelliSense for Amazon ECS Task Definition Files (p. 29)

Using IntelliSense for Amazon ECS Task Definition


Files
One of the things that you might do when working with Amazon Elastic Container Service (Amazon ECS)
is to create task definitions, as described in Creating a Task Definition from the Amazon Elastic Container
Service Developer Guide. When you install the AWS Toolkit for Visual Studio Code, the installation
includes IntelliSense functionality for Amazon ECS task-definition files.

29
AWS Toolkit for VS Code User Guide
Using IntelliSense for Task Definition Files

Prerequisites
• If you haven't already done so, satisfy the prerequisites specified in Installing the Toolkit for VS
Code (p. 2).

Use IntelliSense in Amazon ECS Task-definition Files


The following example shows you how you can take advantage of IntelliSense in Amazon ECS task-
definition files.

1. Create a JSON file for your Amazon ECS task definition. The file's name must have ecs-task-
def.json at the end, but can have additional characters at the beginning.

For this example, create a file named my-ecs-task-def.json


2. Open the file in a VS Code editor and enter the initial curly braces.
3. Enter the letter "c" as if you wanted to add cpu to the definition. Observe the IntelliSense dialog
that opens, which is similar to the following.

30
AWS Toolkit for VS Code User Guide

Document History for the AWS


Toolkit for Visual Studio Code User
Guide
Latest major documentation update: September 25, 2019

The following table describes important changes in each release of the AWS Toolkit for Visual Studio
Code. For notification about updates to this documentation, you can subscribe to an RSS feed.

update-history-change update-history-description update-history-date

Using an External Credential Added information about using September 25, 2019
Process (p. 7) an external credential process to
obtain AWS credentials.

Using IntelliSense for Task IntelliSense support was added September 24, 2019
Definition Files (p. 29) for working with Amazon ECS
task Definition files.

User Guide for the AWS Toolkit Release for general availability. July 11, 2019
for Visual Studio Code (p. 1)

User Guide for the AWS Toolkit Updated the document structure July 3, 2019
for Visual Studio Code (p. 1) for clarity and ease of use.

Installing the AWS Toolkit for VS Added information about June 12, 2019
Code (p. 2) installing language SDKs to
support various toolchains.

Configure Your Toolchain (p. 13) Added information about June 12, 2019
configuring various toolchains.

Initial Release (p. 31) Initial release of the user guide March 28, 2019
for AWS Toolkit for Visual Studio
Code.

31

You might also like