IntelliJ IDEA Plugins Tutorials

AWS in IntelliJ IDEA

In this blog, we’re going to explore how to work with Amazon Web Services (AWS) in IntelliJ IDEA. We’ll start by setting up IntelliJ IDEA to connect to AWS. Then, we’ll highlight a few features that are beneficial when working with AWS from your IDE.

This blog post covers the same material as the video. This provides an easy way for people to skim the content quickly if they prefer reading to watching, and to give the reader/watcher links to additional information.

Setup

To configure IntelliJ IDEA to work with AWS, we need to install the AWS Toolkit for IntelliJ IDEA plugin and configure the AWS credentials required to connect our IDE to AWS.

Installing AWS Toolkit Plugin

In your IntelliJ IDEA Community or Ultimate edition, install the AWS Toolkit plugin by going to your IDE Settings (File -> Settings for Windows/Linux or IntelliJ IDEA -> Preferences for macOS) and navigating to Plugins. Make sure the Marketplace tab is selected then search for AWS Toolkit. Click on the Install button next to the AWS Toolkit search result.

AWS Toolkit Plugin Installation

After the plugin is finished installing, restart your IDE.

After the IDE restarts, you will see a new AWS Explorer tool window. You can also access this window by going to View -> Tool Windows -> AWS Explorer.

AWS Explorer Tool Window

Now that the AWS Toolkit plugin is installed, we need to connect the IDE to our AWS account.

Connecting IntelliJ IDEA to AWS

IntelliJ IDEA uses credential files to connect to an AWS account similar to the AWS Command Line Interface (CLI). If you already have AWS CLI or other AWS tools configured on your machine, IntelliJ IDEA may detect your configuration file and automatically connect to your account. If that’s the case and you see a list of your AWS resources listed in the AWS Explorer window, you can skip to the next section of this tutorial.

On the other hand, if your machine has no credential files and you don’t have any AWS credentials to choose from in the credentials drop-down menu, like the image shown below, click on Edit AWS Credential file(s).

Edit Credentials File Option

Since we currently have no credential files, IntelliJ IDEA will prompt us to create a credential file. We’ll click Create.

A new configuration file is created containing comments at the top describing the contents of the files and fields where we can enter our aws_access_key_id and aws_secret_access_key.

There are a few ways to set up access to AWS. You can find detailed instructions on the different methods in the AWS Toolkit User Guide’s page on connecting the AWS Toolkit to AWS accounts. If your company has an admin team that manages access to AWS, you may need to consult them on how to get command line access. The IDE uses the same credential files as the CLI, so if AWS access works from the command line, it will work in the IDE as well.

In this blog, I’d like to show you how I configured my IDE to connect to AWS in case you’re starting from scratch on your own personal AWS account.

In my browser, I’ll login to my AWS Management Console. Then, I’ll navigate to the Identity and Access Management (IAM) service. In the IAM service page, I will select Users from the left-hand menu. I’ll click the Add users button on the right. Then, fill in the User name. Then, I’ll check the Access key – Programmatic access checkbox which will allow me to use the access key ID and secret access key to connect IntelliJ IDEA and any other command line tools to AWS. Then, I’ll click Next: Permissions.

New IAM User name and access type

In the permissions page, I’ll select Attach existing policies directly and check the AdministratorAccess box. Then, I’ll click Next: Tags.

New IAM User permissions

I don’t need any tags so I’ll click Next: Review.

I’ll review my summary and ensure that all the user details are correct. Then, I’ll click Create user.

Once I do that, I can see that the new IAM user was created. I now have a generated Access key ID and Secret access key to use to connect IntelliJ IDEA to AWS. I’ll copy the Access Key ID and paste it into my config file in the IDE. For the Secret access key, I’ll click on the Show button and copy it over as well.

Access key ID and Secret access key

Note: be careful with your secret access key and don’t share it with anyone since it gives full administrator access to your AWS account.

In IntelliJ IDEA, I’ll click on the Save blue button. Then, in the AWS Explorer window, I’ll click on the credentials drop-down menu. I can now see the Profile:default associated with my credentials. Once I select the default profile, IntelliJ IDEA will load a list of AWS services associated with my AWS account.

AWS Explorer Successful Connection

If you run into any issues during this step, consult the setup instructions in the AWS Toolkit User Guide.

Now that our AWS Toolkit is configured and ready to go, let’s take a look at how to use it.

Working with the AWS Toolkit

AWS connection information can be viewed and modified from two locations: the AWS Explorer window or the status bar.

AWS Connection Information

In the AWS Explorer window, the first drop-down menu will let you select between connections which is useful when you have multiple AWS accounts and you want to switch between them.

The second drop-down menu will let you choose the region you’d like to work with. Select All Regions to see the full list of regions to choose from.

AWS Change Regions

Note: make sure you have the right region selected when browsing your resources in your IDE. There has been a few times when I couldn’t see a certain resource I was expecting and it turned out it was because I didn’t have the right region selected.

AWS Services

In the AWS Explorer window, you’ll see a list of different AWS services that you can interact with from IntelliJ IDEA. Let’s take a look at a few.

CloudWatch Logs

One of the most useful features of the toolkit is the ability to see your CloudWatch Logs right within your IDE. You can do so by expanding the CloudWatch Logs node which will give you a list of your log groups.

View CloudWatch Logs

I’d like to see the logs associated with my guestbook application running in production so I’ll double-click on guestbook/prod which will show me a list of log streams to choose from. Once I select the log stream I’m interested in, I can now see the logs for my application.

CloudWatch Logs for Application

My application is a Spring Boot app so I see the Spring Boot logs showing the application starting. I can also filter events by entering in a string in the Filter events window and clicking Enter.

Another option for searching through the logs is to click on one of the log messages and start typing a string to look for in the logs. You can navigate between the different hits using the arrow keys.

ECR

Another AWS service you can interact with in your IDE is Amazon Elastic Container Registry (ECR).

ECR - View Repositories

You can easily create a new repository by right-clicking on the ECR node.

For existing repositories, you can right-click on your repository to pull or push images.

ECR - Pull and Push to repositories

Lambda

One of the main features of the AWS Toolkit in IntelliJ IDEA is the ability to work with AWS Lambda.

View Lambdas

You can create a new Lambda function by itself by right-clicking on the Lambda node.

Create New Lambda

You can also create a Lambda function that is part of an AWS serverless application by going to the New Project menu and selecting AWS from the left-hand menu.

Create New AWS Serverless Application

Checkout this video to learn about building serverless applications in IntelliJ IDEA.

S3

One of my favorite features of the AWS Toolkit is the ability to browse my S3 buckets right within my IDE. I can do that by expanding the S3 node.

View S3 Buckets

I can create a new S3 bucket by right-clicking on the S3 node and clicking Create S3 bucket.

For my existing buckets, I can view the contents by double-clicking on my bucket. From there, I select the files in my bucket to download and view them.

View S3 Bucket Contents

View S3 Bucket Content Image

Other Services

The services we’ve highlighted so far are just a few of many services that you can interact with from your IDE. Once you have your AWS Toolkit connected to your IDE, I recommend that you browse through the services you’re using for your application and see what you can do with them.

You can also use the Resources node to choose from hundreds of additional resource types and interact with them from your IDE.

AWS Toolkit Settings

We can view additional settings for the AWS Toolkit using the Settings icon in the AWS Explorer window. If you click on the icon, you’ll see some helpful links including a documentation link which points you to the AWS Toolkit User Guide as well as a link to the AWS Toolkit GitHub repository.

Additional Settings

An interesting option available in the settings menu is the ability to enable experimental features. For example, one feature that I’ve heard great feedback on is the ability to open an AWS local terminal within your IDE. You can enable this feature by selecting Experimental Features -> Open AWS local terminal. Once you do that, a new terminal icon will appear in the AWS Explorer. If you click on the new terminal icon, IntelliJ IDEA will start a local terminal session with your current AWS credentials which means you can run commands like aws s3 ls to list all your S3 buckets.

Terminal Feature

In this tutorial, we explored some of the IntelliJ IDEA features that make it easier for you to work with AWS. I hope you install the AWS Toolkit for IntelliJ IDEA plugin and try it out!

See also:

Discover more

IntelliJ IDEA Plugins Tutorials

IntelliJ IDEA 中的 AWS

在本博文中,我们将探讨如何在 IntelliJ IDEA 中使用 Amazon Web Services (AWS)。首先,我们将设置 IntelliJ IDEA 以连接到 AWS。然后,我们将重点介绍一些在 IDE 中使用 AWS 时非常有用的功能。
 

本篇博文与视频涵盖相同的材料。对于喜欢阅读文章而不喜欢观看视频的读者,可以通过本文快速浏览内容。读者/观看者也可以在本文中获得指向其他信息的链接。

安装

要配置 IntelliJ IDEA 以使用 AWS,我们需要安装 AWS Toolkit for IntelliJ IDEA 插件,并配置将 IDE 连接到 AWS 所需的 AWS 凭据。

安装 AWS Toolkit 插件

要在您的 IntelliJ IDEA Community Edition 或 Ultimate Edition 中安装 AWS Toolkit 插件,请转到 IDE 设置(Windows/Linux:File -> Settings(文件 -< 设置);macOS:IntelliJ IDEA -> Preferences(IntelliJ IDEA -< 偏好设置)),并导航到 Plugins(插件)。确保选择 Marketplace 选项卡,然后搜索 AWS Toolkit。点击 AWS Toolkit 搜索结果旁边的 Install(安装)按钮。

AWS Toolkit Plugin Installation

插件安装完成后,重新启动 IDE。
 
IDE 重新启动后,您将看到一个新的 AWS Explorer 工具窗口。您还可以通过转到 View -> Tool Windows -> AWS Explorer(视图 -< 工具窗口 -< AWS Explorer)访问此窗口。

AWS Explorer Tool Window

现在已安装 AWS Toolkit 插件,我们需要将 IDE 连接到我们的 AWS 帐户。
 

将 IntelliJ IDEA 连接到 AWS

IntelliJ IDEA 使用凭据文件连接到 AWS 帐户,类似于 AWS 命令行界面 (CLI)。如果您的计算机上已经配置了 AWS CLI 或其他 AWS 工具,IntelliJ IDEA 可能会检测到您的配置文件并自动连接到您的帐户。如果是这种情况,并且您在 AWS Explorer 窗口中看到了您的 AWS 资源列表,则可以跳到本教程的下一部分。
 
另一方面,如果您的计算机没有凭据文件,并且您在凭据下拉菜单中没有看到任何 AWS 凭据可供选择,如下图所示,请点击 Edit AWS Credential file(s)(编辑 AWS 凭据文件)。

Edit Credentials File Option

由于我们当前没有凭据文件,IntelliJ IDEA 将提示我们创建凭据文件。点击 Create(创建)。
 
随后将创建一个新的配置文件,其顶部包含注释,描述文件和字段的内容,我们可以在其中输入 aws_access_key_idaws_secret_access_key
 
可以通过几种方式设置对 AWS 的访问。您可以在 AWS Tookit 用户指南的将 AWS Toolkit 连接到 AWS 帐户页面上找到不同方法的详细说明。如果您的公司有一个管理 AWS 访问权限的管理团队,您可能需要向他们咨询如何获得命令行访问权限。IDE 使用与 CLI 相同的凭据文件,因此如果 AWS 访问权限在命令行中有效,在 IDE 中也会有效。
 
在此博文中,我想向您展示配置 IDE 以连接到 AWS 的方法,方便您使用自己的 AWS 帐户从头开始。
 
在浏览器中登录 AWS 管理控制台。然后,导航到 Identity and Access Management (IAM) 服务。在 IAM 服务页面上,从左侧菜单中选择 Users(用户)。点击右侧的 Add users(添加用户)按钮。然后填入 User name(用户名)。然后,勾选 Access key – Programmatic access(访问密钥 – 以编程方式访问)复选框,这将允许我使用访问密钥 ID 和秘密访问密钥将 IntelliJ IDEA 和任何其他命令行工具连接到 AWS。然后点击 Next: Permissions(下一步:权限)。
 
 
在权限页面上,选择 Attach existing policies directly(直接附加现有策略),然后选中 AdministratorAccess 复选框。然后点击 Next: Tags(下一步:标签)。

New IAM User permissions不需要任何标签,因此点击 Next: Review(下一步:检查)。

检查摘要,并确保所有用户详细信息正确。然后点击 Create user(创建用户)。

完成此操作后,可以看到新建的 IAM 用户。现在,我们有了生成的访问密钥 ID 和秘密访问密钥,可以用来将 IntelliJ IDEA 连接到 AWS。复制 Access Key ID 并将其粘贴到 IDE 的配置文件中。对于 Secret access key,点击 Show(显示)按钮并复制。

Access key ID and Secret access key

注意:请妥善保管您的秘密访问密钥,不要与任何人分享,因为它能授予您的 AWS 帐户的完全管理员访问权限。
 
在 IntelliJ IDEA 中,点击蓝色的 Save(保存)按钮。然后,在 AWS Explorer 窗口中,点击凭据下拉菜单。现在可以看到与我的凭据关联的 Profile:default。选择默认配置文件后,IntelliJ IDEA 将加载与我的 AWS 帐户关联的 AWS 服务列表。

AWS Explorer Successful Connection

如果在此步骤中遇到任何问题,请参阅 AWS Toolkit 用户指南中的设置说明
 
现在,我们的 AWS Toolkit 已配置完成并准备就绪,让我们来看看如何使用。

使用 AWS Toolkit

可以从两个位置查看和修改 AWS 连接信息:AWS Explorer 窗口或状态栏。

AWS Connection Information

AWS Explorer 窗口中,您可以使用第一个下拉菜单在连接之间进行选择,这在您有多个 AWS 帐户并希望在它们之间切换时非常有用。
 
您可以使用第二个下拉菜单来选择要使用的区域。选择 All Regions(所有区域)可以查看可选择区域的完整列表。

AWS Change Regions

注意:在 IDE 中浏览资源时,请确保选择正确区域。有几次我看不到我想要的某个资源,结果是因为我没有选择正确的区域。

AWS 服务

AWS Explorer 窗口中,您将看到 IntelliJ IDEA 提供的可供交互的不同 AWS 服务的列表。
我们来看几个服务。
 

CloudWatch 日志

该工具包最有用的功能之一是能够在 IDE 中查看 CloudWatch 日志。为此,您可以展开 CloudWatch Logs(CloudWatch 日志)节点,该节点将为您提供日志组列表。

View CloudWatch Logs

我希望看到与在生产环境中运行的留言板应用程序相关联的日志,因此我将双击guestbook/prod,这将显示一个可供选择的日志流列表。在选择感兴趣的日志流后,就可以看到我的应用程序的日志了。

CloudWatch Logs for Application

我的应用程序是一款 Spring Boot 应用,所以我看到 Spring Boot 日志显示应用程序正在启动。我还可以通过在 Filter(筛选)事件窗口中输入字符串并点击 Enter 来筛选事件。
 
搜索日志的另一个选项是点击其中一条日志消息,然后开始输入要在日志中查找的字符串。
您可以使用方向键在不同的候选项之间导航。
 

ECR

您可以在 IDE 中与之交互的另一项 AWS 服务是 Amazon Elastic Container Registry (ECR)

ECR - View Repositories

您可以通过右键点击 ECR 节点轻松创建新的仓库。
 
对于现有仓库,您可以右键点击仓库以拉取或推送映像。

ECR - Pull and Push to repositories

Lambda

IntelliJ IDEA 中的 AWS Toolkit 的主要功能之一是能够使用 AWS Lambda

View Lambdas

您可以通过右键点击 Lambda 节点来创建一个新的 Lambda 函数。

Create New Lambda

您还可以通过转到 New Project(新建项目)菜单并从左侧菜单中选择 AWS 来创建作为 AWS 无服务器应用程序一部分的 Lambda 函数。

Create New AWS Serverless Application

查看此视频,了解如何在 IntelliJ IDEA 中构建无服务器应用程序。
 

S3

我最喜欢的 AWS Toolkit 功能之一是能够直接在 IDE 中浏览我的 S3 存储桶。
可以通过展开 S3 节点来实现。

View S3 Buckets

我可以通过右键点击 S3 节点并点击 Create S3 bucket(创建 S3 存储桶)来创建新的 S3 存储桶。
 
对于我现有的存储桶,我可以通过双击存储桶来查看内容。我可以从那里选择存储桶中的文件进行下载和查看。

View S3 Bucket Contents

View S3 Bucket Content Image

其他服务

到目前为止,我们重点介绍的服务只是您可以从 IDE 与之交互的众多服务中的一小部分。将 AWS Toolkit 连接到 IDE 后,建议浏览您的应用程序正在使用的服务,看看您可以对它们进行哪些操作。
 
您还可以使用 Resources(资源)节点从数百种其他资源类型中进行选择,并从 IDE 与它们进行交互。

AWS Toolkit 设置

我们可以使用 AWS Explorer 窗口中的设置图标查看 AWS Tookit 的其他设置。如果点击该图标,您将看到一些有用的链接,其中包括指向 AWS Toolkit 用户指南的文档链接,以及指向 AWS Toolkit GitHub 仓库的链接。

Additional Settings

设置菜单中一个有趣的选项是启用实验性功能。例如,我听说反馈很好的一个功能是能够在您的 IDE 中打开 AWS 本地终端。您可以通过选择 Experimental Features -> Open AWS local terminal(实验性功能 -< 打开 AWS 本地终端)来启用此功能。完成此操作后,AWS Explorer 中将显示一个新的终端图标。如果您点击新终端图标,IntelliJ IDEA 将使用您当前的 AWS 凭据启动本地终端会话,这意味着您可以运行像 AWS s3 ls 这样的命令来列出您所有的 S3 存储桶。

Terminal Feature

在本教程中,我们探索了 IntelliJ IDEA 的一些功能,这些功能使您可以更轻松地使用 AWS。
我希望您能安装 AWS Toolkit for IntelliJ IDEA 插件,亲自尝试一下!
 
另请参阅:

英文博文原作者:

Discover more