|
| 1 | +# Infrastructure for SageMaker Workshop with a CDK solution stack |
| 2 | + |
| 3 | +This folder provides a helper stack which will: |
| 4 | + |
| 5 | +- Create a SageMaker Notebook Instance with the repository cloned in |
| 6 | +- Create an (IAM-authenticated) SageMaker Studio domain, with a user profile, with the repository cloned in (and some VPC infrastructure required to make that happen) |
| 7 | +- Run a one-off AWS CodeBuild build to download the repository, `poetry install` the dependencies and `cdk deploy --all` stacks in the solution |
| 8 | + |
| 9 | +It's intended to help automate setting up workshops on temporary AWS accounts, with CDK-based solutions (like this one) that assume a SageMaker notebook environment will be provisioned separately. |
| 10 | + |
| 11 | +## Prerequisites and Caveats |
| 12 | + |
| 13 | +This helper stack assumes that (in your target AWS Region): |
| 14 | + |
| 15 | +- You have not yet onboarded to SageMaker Studio |
| 16 | +- You have a default VPC you're willing to use with standard configuration, or else would like to use a custom VPC but are comfortable checking the compatibility of the stack with your VPC configuration. |
| 17 | + |
| 18 | +> ⚠️ This stack is oriented towards convenience of **getting started** and first exploring SageMaker Studio with the companion solution stack. It is **not recommended for long-lived environments**. |
| 19 | +> |
| 20 | +> In particular, **be aware that:** |
| 21 | +> |
| 22 | +> - The stack grants broad power user permissions to the CodeBuild job (for whatever resources the CDK deployment may need to create) |
| 23 | +> - When you delete the stack |
| 24 | +> - The SageMaker Studio setup for your target AWS Region will be deleted (and the stack should *fail* to delete if you have any users running 'apps' in Studio apart from the ones set up by the stack. You can manage these through the [SageMaker console UI](https://console.aws.amazon.com/sagemaker/home?#/studio)) |
| 25 | +> - The CDK solution deployed deployed by the CodeBuild project will *not* automatically be cleaned up |
| 26 | +
|
| 27 | +## Developing and Deploying Locally |
| 28 | + |
| 29 | +In addition to having an AWS account, you'll need an environment with: |
| 30 | + |
| 31 | +- The [AWS CLI](https://aws.amazon.com/cli/) |
| 32 | +- The [AWS SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) |
| 33 | +- A Docker-compatible container runtime such as [Docker Desktop](https://www.docker.com/products/docker-desktop) |
| 34 | +- A `make` utility such as [GNU Make](https://www.gnu.org/software/make/) - probably already installed if you have some bundled build tools already. |
| 35 | +- *Probably* a UNIX-like (non-Windows) shell if you want things to run smoothly... But you can always give it a try and resort to translating commands from the [Makefile](Makefile) if things go wrong. |
| 36 | + |
| 37 | +You'll also need: |
| 38 | + |
| 39 | +- Sufficient access (log in with `aws configure`) to be able to deploy the stacks in your target region |
| 40 | +- An *[Amazon S3](https://s3.console.aws.amazon.com/s3/home) Bucket* to use for staging deployment assets (Lambda bundles, etc) |
| 41 | + |
| 42 | +**Step 1: Build the Lambda bundles and final CloudFormation template to S3 with AWS SAM** |
| 43 | + |
| 44 | +(This command builds your assets and CloudFormation template, and stages them to your nominated Amazon S3 bucket) |
| 45 | + |
| 46 | +```sh |
| 47 | +make package DEPLOYMENT_BUCKET_NAME=DOC-EXAMPLE-BUCKET |
| 48 | +``` |
| 49 | + |
| 50 | +**Step 2: Deploy (create or update) the stack** |
| 51 | + |
| 52 | +```sh |
| 53 | +make deploy STACK_NAME=workshopstack |
| 54 | +``` |
| 55 | + |
| 56 | +***Alternative: Build and create the stack in one go** |
| 57 | + |
| 58 | +(This option only *creates* stacks, and disables rollback, for easier debugging) |
| 59 | + |
| 60 | +```sh |
| 61 | +make all DEPLOYMENT_BUCKET_NAME=example-bucket STACK_NAME=workshopstack |
| 62 | +``` |
| 63 | + |
| 64 | +There's also a `make delete` option to help with cleaning up. |
| 65 | + |
| 66 | +## Preparing Templates for Multi-Region Deployment |
| 67 | + |
| 68 | +If you'd like your template to be deployable in multiple AWS Regions: |
| 69 | + |
| 70 | +- Set up an asset hosting bucket in each region of interest, and use the AWS Region ID (e.g. `us-east-1`) in the bucket names |
| 71 | +- Set up cross-region replication to copy contents from your lead region to other regions |
| 72 | +- Run the `make package` script against your lead region |
| 73 | + |
| 74 | +The generated template will be automatically post-processed (by [sam-postproc.py](sam-postproc.py)) to tokenize S3 references to hosted assets to refer to the `${AWS::Region}` placeholder. |
0 commit comments