Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions keyvalue-store-in-secretsmgr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import boto3

def lambda_handler(event, context):
# Replace 'YOUR_SECRET_NAME' with the actual name of your secret in AWS Secrets Manager
secret_name = 'YOUR_SECRET_NAME'

# Replace 'YOUR_KEY' and 'YOUR_VALUE' with the actual key-value pair you want to store
key = 'YOUR_KEY'
value = 'YOUR_VALUE'

# Create a Secrets Manager client
client = boto3.client('secretsmanager')

# Create or update the secret with the key-value pair
response = client.put_secret_value(SecretId=secret_name, SecretString={key: value})

# Return the response
return response
10 changes: 10 additions & 0 deletions sagemaker/cfn-create-sagemaker-domain.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
AWSTemplateFormatVersion: "2010-09-09"
Description: CloudFormation template for Amazon SageMaker domain creation

Resources:
SageMakerDomainCustomResource:
Type: Custom::SageMakerDomain
Properties:
ServiceToken: ARN_OF_YOUR_LAMBDA_FUNCTION
# Add any input parameters you want to pass to the Lambda function

29 changes: 29 additions & 0 deletions sagemaker/cfn-create-sagemaker-instance.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
AWSTemplateFormatVersion: "2010-09-09"
Description: CloudFormation template for Amazon SageMaker notebook instance

Resources:
SageMakerNotebookInstance:
Type: AWS::SageMaker::NotebookInstance
Properties:
NotebookInstanceName: MySageMakerNotebook
InstanceType: ml.t2.medium
RoleArn: !GetAtt SageMakerNotebookRole.Arn
# You can add more properties here, such as SubnetId, SecurityGroupIds, etc.

SageMakerNotebookRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: Allow
Principal:
Service: sagemaker.amazonaws.com
Action: sts:AssumeRole

# Add more permissions for the SageMaker role if needed.
# For example, you may need permissions to access S3 buckets or other resources.

Outputs:
SageMakerNotebookInstanceName:
Value: !Ref SageMakerNotebookInstance
36 changes: 36 additions & 0 deletions sagemaker/lambda-execution-role.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "SageMakerPermissions",
"Effect": "Allow",
"Action": [
"sagemaker:CreateEndpoint",
"sagemaker:UpdateEndpoint",
"sagemaker:DeleteEndpoint",
"sagemaker:InvokeEndpoint",
"sagemaker:CreateModel",
"sagemaker:DeleteModel",
"sagemaker:CreateEndpointConfig",
"sagemaker:DeleteEndpointConfig",
"sagemaker:CreateTransformJob",
"sagemaker:CreateProcessingJob",
"sagemaker:Describe*",
"sagemaker:List*",
"sagemaker:Stop*"
],
"Resource": "*"
},
{
"Sid": "S3Permissions",
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:DeleteObject"
],
"Resource": "arn:aws:s3:::YOUR_S3_BUCKET/*"
}
]
}

13 changes: 13 additions & 0 deletions sagemaker/notes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Creation of the SageMaker Domain is not straight forward.

Create the Lambda Function:
Create an AWS Lambda function that uses the Boto3 library to create the SageMaker domain. The Lambda function will be responsible for the actual domain creation and handling the CloudFormation custom resource request.

CloudFormation Custom Resource:
In your CloudFormation template, define a custom resource that references the Lambda function you created in the previous step. The custom resource acts as a bridge between CloudFormation and the Lambda function.

Lambda Execution Role:
Ensure that the Lambda function has the necessary IAM permissions to create a SageMaker domain. Create an IAM role with the required permissions and attach it to the Lambda function.

CloudFormation Stack:
Deploy your CloudFormation stack, which includes the custom resource. When the stack is created, the custom resource triggers the Lambda function to create the SageMaker domain.