Skip to content

Commit de33bb7

Browse files
HweinstockJadenSimonWeinstockjustinmk3
authored
feat(ec2): provide link to launch instance. (#3697)
## Problem User Request ## Solution Add option to launch instance from toolkit. The option links to console page for launching EC2 instances. Currently, the functionality is available as an icon-button and on right-click. Additionally, we have it in the command-palette. In the command palette, the region is inferred using `guessDefaultRegion`. I see three potential alternatives: - (1)provide a region prompter when used from the command palette that defaults to the region given by `guessDefaultRegion`. - (2)Don't prompt for region, and assume the region based on `guessDefaultRegion`. - (3)Don't allow the command to be used from command palette and only see it on the explorer. Let me know if you think either of the alternatives presented above would be preferred. The current implementation (1) because it seems like the optimal middle ground. We allow the customer to select their region, while also providing an intuitive and helpful default. Below are some screenshots of the feature: <img width="743" alt="image" src="https://github.com/user-attachments/assets/3f56800c-ca95-4f82-be48-76d353ad92ad"> <img width="530" alt="image" src="https://github.com/user-attachments/assets/088da856-7bbc-4e3f-98bf-1028372111bf"> <img width="691" alt="image" src="https://github.com/user-attachments/assets/a09367d2-cd41-4f6a-804f-fb7327041f53"> <!--- REMINDER: - Read CONTRIBUTING.md first. - Add test coverage for your changes. - Update the changelog using `npm run newChange`. - Link to related issues/commits. - Testing: how did you test your changes? - Screenshots --> ## License By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. --------- Co-authored-by: JadenSimon <[email protected]> Co-authored-by: Weinstock <[email protected]> Co-authored-by: Justin M. Keyes <[email protected]>
1 parent a969253 commit de33bb7

File tree

6 files changed

+52
-1
lines changed

6 files changed

+52
-1
lines changed

packages/core/package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1189,6 +1189,10 @@
11891189
"command": "aws.ec2.openTerminal",
11901190
"when": "aws.isDevMode"
11911191
},
1192+
{
1193+
"command": "aws.ec2.linkToLaunch",
1194+
"when": "aws.isDevMode"
1195+
},
11921196
{
11931197
"command": "aws.ec2.startInstance",
11941198
"when": "aws.isDevMode"
@@ -1411,6 +1415,16 @@
14111415
"group": "inline@1",
14121416
"when": "viewItem =~ /^(awsEc2(Parent|Running)Node)$/"
14131417
},
1418+
{
1419+
"command": "aws.ec2.linkToLaunch",
1420+
"group": "0@1",
1421+
"when": "viewItem =~ /^(awsEc2ParentNode)$/"
1422+
},
1423+
{
1424+
"command": "aws.ec2.linkToLaunch",
1425+
"group": "inline@1",
1426+
"when": "viewItem =~ /^(awsEc2ParentNode)$/"
1427+
},
14141428
{
14151429
"command": "aws.ec2.openRemoteConnection",
14161430
"group": "0@1",
@@ -2253,6 +2267,18 @@
22532267
}
22542268
}
22552269
},
2270+
{
2271+
"command": "aws.ec2.linkToLaunch",
2272+
"title": "%AWS.command.ec2.linkToLaunch%",
2273+
"icon": "$(add)",
2274+
"category": "%AWS.title%",
2275+
"enablement": "isCloud9 || !aws.isWebExtHost",
2276+
"cloud9": {
2277+
"cn": {
2278+
"category": "%AWS.title.cn%"
2279+
}
2280+
}
2281+
},
22562282
{
22572283
"command": "aws.ec2.openRemoteConnection",
22582284
"title": "%AWS.command.ec2.openRemoteConnection%",

packages/core/package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
"AWS.command.ec2.openTerminal": "Open terminal to EC2 instance...",
125125
"AWS.command.ec2.openRemoteConnection": "Connect to EC2 instance in New Window...",
126126
"AWS.command.ec2.startInstance": "Start EC2 Instance",
127+
"AWS.command.ec2.linkToLaunch": "Launch EC2 Instance",
127128
"AWS.command.ec2.stopInstance": "Stop EC2 Instance",
128129
"AWS.command.ec2.rebootInstance": "Reboot EC2 Instance",
129130
"AWS.command.ec2.copyInstanceId": "Copy Instance Id",

packages/core/src/awsService/ec2/activation.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
startInstance,
1616
stopInstance,
1717
refreshExplorer,
18+
linkToLaunchInstance,
1819
} from './commands'
1920

2021
export async function activate(ctx: ExtContext): Promise<void> {
@@ -56,6 +57,12 @@ export async function activate(ctx: ExtContext): Promise<void> {
5657
await rebootInstance(node)
5758
refreshExplorer(node)
5859
})
60+
}),
61+
62+
Commands.register('aws.ec2.linkToLaunch', async (node?: Ec2Node) => {
63+
await telemetry.ec2_launchInstance.run(async (span) => {
64+
await linkToLaunchInstance(node)
65+
})
5966
})
6067
)
6168
}

packages/core/src/awsService/ec2/commands.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import { Ec2Prompter, instanceFilter, Ec2Selection } from './prompter'
1010
import { SafeEc2Instance, Ec2Client } from '../../shared/clients/ec2Client'
1111
import { copyToClipboard } from '../../shared/utilities/messages'
1212
import { getLogger } from '../../shared/logger'
13+
import { getAwsConsoleUrl } from '../../shared/awsConsole'
14+
import { showRegionPrompter } from '../../auth/utils'
15+
import { openUrl } from '../../shared/utilities/vsCodeUtils'
1316

1417
export function refreshExplorer(node?: Ec2Node) {
1518
if (node) {
@@ -53,6 +56,12 @@ export async function rebootInstance(node?: Ec2Node) {
5356
await client.rebootInstanceWithCancel(selection.instanceId)
5457
}
5558

59+
export async function linkToLaunchInstance(node?: Ec2Node) {
60+
const region = node ? node.regionCode : (await showRegionPrompter('Select Region', '')).id
61+
const url = getAwsConsoleUrl('ec2-launch', region)
62+
await openUrl(url)
63+
}
64+
5665
async function getSelection(node?: Ec2Node, filter?: instanceFilter): Promise<Ec2Selection> {
5766
const prompter = new Ec2Prompter(filter)
5867
const selection = node && node instanceof Ec2InstanceNode ? node.toSelection() : await prompter.promptUser()

packages/core/src/shared/awsConsole.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,16 @@
55

66
import * as vscode from 'vscode'
77

8-
export function getAwsConsoleUrl(service: 'ecr' | 'cloudformation', region: string): vscode.Uri {
8+
export function getAwsConsoleUrl(service: 'ecr' | 'cloudformation' | 'ec2-launch', region: string): vscode.Uri {
99
switch (service) {
1010
case 'ecr':
1111
return vscode.Uri.parse(`https://${region}.console.aws.amazon.com/ecr/repositories?region=${region}`)
1212
case 'cloudformation':
1313
return vscode.Uri.parse(`https://${region}.console.aws.amazon.com/cloudformation/home?region=${region}`)
14+
case 'ec2-launch':
15+
return vscode.Uri.parse(
16+
`https://${region}.console.aws.amazon.com/ec2/home?region=${region}#LaunchInstances:`
17+
)
1418
default:
1519
throw Error()
1620
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Feature",
3+
"description": "EC2: Launch ec2 instances from AWS Explorer"
4+
}

0 commit comments

Comments
 (0)