forked from aws-solutions/research-service-workbench-on-aws
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsagemakerNotebookEnvironmentConnectionService.ts
45 lines (41 loc) · 1.57 KB
/
sagemakerNotebookEnvironmentConnectionService.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
import { AwsService } from '@aws/workbench-core-base';
import {
EnvironmentConnectionService,
EnvironmentConnectionLinkPlaceholder
} from '@aws/workbench-core-environments';
export default class SagemakerNotebookEnvironmentConnectionService implements EnvironmentConnectionService {
/**
* Get credentials for connecting to the environment
*/
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
public async getAuthCreds(instanceName: string, context?: any): Promise<any> {
const region = process.env.AWS_REGION!;
const awsService = new AwsService({ region });
const hostingAccountAwsService = await awsService.getAwsServiceForRole({
roleArn: context.roleArn,
roleSessionName: `SagemakerConnect-${Date.now()}`,
externalId: context.externalId,
region
});
const response = await hostingAccountAwsService.clients.sagemaker.createPresignedNotebookInstanceUrl({
NotebookInstanceName: instanceName
});
return { url: response.AuthorizedUrl };
}
/**
* Instructions for connecting to the workspace that can be shown verbatim in the UI
*/
public getConnectionInstruction(): Promise<string> {
// "url" is the key of the response returned by the method `getAuthCreds`
const link: EnvironmentConnectionLinkPlaceholder = {
type: 'link',
hrefKey: 'url',
text: 'Sagemaker URL'
};
return Promise.resolve(`To access Sagemaker Notebook, open #${JSON.stringify(link)}`);
}
}