- Create a new CloudFormation template file.
- Add the following resources to the template file:
Replace <my-kms-key-id>
with the ID of your pre-configured AWS KMS key.
To deploy this template using the AWS CLI, you can use the create-stack
command:
aws cloudformation create-stack --stack-name MySageMakerStack --template-body file://sagemaker-stack.yaml
AWS CLI:
aws cloudformation deploy
–template-file notebook-instance.yaml
–stack-name notebook-instance-stack
–parameters ParameterKey=InstanceType,ParameterValue=ml.t2.medium ParameterKey=KmsKeyId,ParameterValue=<my-kms-key-id>
Boto3:
Python
import boto3
client = boto3.client('cloudformation')
template = '''
AWSTemplateFormatVersion: 2010-09-09
Parameters:
InstanceType:
Type: String
Default: ml.t2.medium
KmsKeyId:
Type: String
Resources:
NotebookInstance:
Type: AWS::SageMaker::NotebookInstance
Properties:
InstanceType: !Ref InstanceType
VolumeSizeInGB: 50
KmsKeyId: !Ref KmsKeyId
Outputs:
NotebookInstanceUrl:
Value: !Ref NotebookInstance
Export:
Name: NotebookInstanceUrl
'''
response = client.create_stack(
StackName='notebook-instance-stack',
TemplateBody=template,
Parameters=[
{
'ParameterKey': 'InstanceType',
'ParameterValue': 'ml.t2.medium'
},
{
'ParameterKey': 'KmsKeyId',
'ParameterValue': '<my-kms-key-id>'
}
]
)
stack_id = response['StackId']
client.wait_for_stack_status_complete(
StackName=stack_id
)
output = client.describe_stacks(
StackName=stack_id
)['Stacks'][0]['Outputs'][0]
notebook_instance_url = output['OutputValue']
print(notebook_instance_url)
Use code with caution. Learn morecontent_copy
This code will create a new CloudFormation stack and launch a notebook instance using the pre-configured AWS KMS key. You can then access the notebook instance using the URL in the NotebookInstanceUrl
output.
To create a portfolio in the AWS Service Catalog and upload samples to share with scientists’ IAM roles:
- Open the AWS Service Catalog console.
- Click Create new portfolio.
- Enter a name and description for the portfolio.
- Click Create portfolio.
Once the portfolio is created, you can upload samples to share with scientists’ IAM roles by following these steps:
- Open the AWS Service Catalog console.
- Select the portfolio you created in the previous step.
- Click Products.
- Click the Import product button.
- Select the CloudFormation template product type.
- Click Next.
- Upload your CloudFormation template file.
- Click Next.
- Configure the product settings.
- Click Create product.
Once the product is created, you can upload samples to share with scientists’ IAM roles by following these steps:
- Open the AWS Service Catalog console.
- Select the product you created in the previous step.
- Click Versions.
- Click Create new version.
- Upload your sample files.
- Click Create version.
You can then assign the product to scientists’ IAM roles so that they can access and use the samples.