Skip to content

Commit ab27975

Browse files
committed
implement main functionality
1 parent baf59d2 commit ab27975

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

src/ec2/activation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export async function activate(ctx: ExtContext): Promise<void> {
4444
await refreshExplorer(node)
4545
}),
4646

47-
Commands.register('aws.ec2.linkToLaunchInstance', async () => {
47+
Commands.register('aws.ec2.linkToLaunchInstance', async (node?: Ec2Node) => {
4848
console.log('you just ran the linkToLaunch command!')
4949
await linkToLaunchInstance()
5050
})

src/ec2/commands.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
* SPDX-License-Identifier: Apache-2.0
44
*/
5-
import * as vscode from 'vscode'
65
import { InstanceStateManager, getStateManagerForSelection } from './instanceStateManager'
76
import { Ec2InstanceNode } from './explorer/ec2InstanceNode'
87
import { Ec2Node } from './explorer/ec2ParentNode'
@@ -11,6 +10,8 @@ import { Ec2Prompter, instanceFilter } from './prompter'
1110
import { Ec2Selection } from './utils'
1211
import { Ec2Instance } from '../shared/clients/ec2Client'
1312
import { openUrl } from '../shared/utilities/vsCodeUtils'
13+
import { getAwsConsoleUrl } from '../shared/awsConsole'
14+
import globals from '../shared/extensionGlobals'
1415

1516
export async function refreshExplorer(node?: Ec2Node) {
1617
await node?.refreshNode()
@@ -47,8 +48,10 @@ export async function rebootInstance(node?: Ec2Node) {
4748
await stateManager.rebootInstanceWithCancel()
4849
}
4950

50-
export async function linkToLaunchInstance() {
51-
const url = vscode.Uri.parse('https://google.com')
51+
export async function linkToLaunchInstance(node?: Ec2Node) {
52+
// Ex. https://us-west-2.console.aws.amazon.com/ec2/home?region=us-west-2#LaunchInstances:
53+
const region = node ? node.regionCode : globals.regionProvider.guessDefaultRegion()
54+
const url = getAwsConsoleUrl('ec2', region)
5255
await openUrl(url)
5356
}
5457

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', 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':
15+
return vscode.Uri.parse(
16+
`https://${region}.console.aws.amazon.com/ec2/home?region=${region}#LaunchInstances:`
17+
)
1418
default:
1519
throw Error()
1620
}

0 commit comments

Comments
 (0)