Skip to content

Commit 9ae9dda

Browse files
Moving CDK app into package
1 parent 7bf031e commit 9ae9dda

21 files changed

+59
-42
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
__pycache__
1515
/tests/output/
1616
/tests/.pytest_cache/
17+
/cdk.out/

.gitlab-ci.yml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ run_tests:
77
stage: test
88
resource_group: ssh-helper-tests
99
script:
10+
- export AWS_REGION=eu-west-1
11+
- export AWS_DEFAULT_REGION=eu-west-1
1012
# Install the package
1113
- pip freeze --all | tee pip_freeze_before.txt
1214
- pip install '.'
@@ -25,15 +27,23 @@ run_tests:
2527
- apt-get install -y nodejs
2628
- npm install -g aws-cdk
2729
- cdk --version
28-
- cd cdk
30+
- REGION=$AWS_REGION
2931
- USER_ROLE=$GITLAB_ROLE_ARN
30-
- cdk deploy SSH-IAM-SSM-Stack-Tests --require-approval never -c sagemaker_role=$SAGEMAKER_ROLE -c user_role=$USER_ROLE
31-
- cdk deploy SSH-IAM-SSM-Stack --require-approval never -c sagemaker_role=$SAGEMAKER_ROLE -c user_role=$USER_ROLE
32-
- cdk deploy SSM-Advanced-Tier-Stack --require-approval never -c sagemaker_role=$SAGEMAKER_ROLE -c user_role=$USER_ROLE
33-
- AWS_REGION=eu-west-2 cdk deploy SSM-Advanced-Tier-Stack --require-approval never -c sagemaker_role=$SAGEMAKER_ROLE -c user_role=$USER_ROLE
34-
- cd -
32+
- APP="python -m sagemaker_ssh_helper.cdk.app"
33+
# cdk bootstrap aws://"$ACCOUNT_ID"/"$REGION" --require-approval never
34+
- AWS_REGION=$REGION cdk -a "$APP" deploy SSH-IAM-SSM-Stack-Tests
35+
--require-approval never -c sagemaker_role=$SAGEMAKER_ROLE -c user_role=$USER_ROLE
36+
- AWS_REGION=$REGION cdk -a "$APP" deploy SSH-IAM-SSM-Stack
37+
--require-approval never -c sagemaker_role=$SAGEMAKER_ROLE -c user_role=$USER_ROLE
38+
- AWS_REGION=$REGION cdk -a "$APP" deploy SSM-Advanced-Tier-Stack
39+
--require-approval never -c sagemaker_role=$SAGEMAKER_ROLE -c user_role=$USER_ROLE
40+
- REGION=eu-west-2
41+
# cdk bootstrap aws://"$ACCOUNT_ID"/"$REGION" --require-approval never
42+
- AWS_REGION=$REGION cdk -a "$APP" deploy SSM-Advanced-Tier-Stack
43+
--require-approval never -c sagemaker_role=$SAGEMAKER_ROLE -c user_role=$USER_ROLE
3544
# Configure local env
3645
- sm-local-configure
46+
- source tests/generate_sagemaker_config.sh
3747
# Assume CI/CD role
3848
- sts=( $(
3949
aws sts assume-role

.idea/sagemaker-ssh-helper.iml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

IAM_SSM_Setup.md

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,17 @@ Note that if you connect to AWS from your local CLI as an IAM user, you will nee
2828
b. Execute the following commands (you can copy-paste them as a whole script):
2929

3030
```shell
31-
git clone --depth 1 https://github.com/aws-samples/sagemaker-ssh-helper.git
31+
pip install 'sagemaker-ssh-helper[cdk]'
3232

33-
cd sagemaker-ssh-helper/
34-
pip install '.[cdk]'
33+
APP="python -m sagemaker_ssh_helper.cdk.app"
3534

36-
cd cdk/
35+
cdk bootstrap aws://"$ACCOUNT_ID"/"$REGION"
3736

38-
cdk bootstrap aws://"$ACCOUNT_ID"/"$REGION" \
37+
AWS_REGION="$REGION" cdk -a "$APP" deploy SSH-IAM-SSM-Stack \
3938
-c sagemaker_role="$SAGEMAKER_ROLE_ARN" \
4039
-c user_role="$USER_ROLE_ARN"
4140

42-
cdk deploy SSH-IAM-SSM-Stack \
43-
-c sagemaker_role="$SAGEMAKER_ROLE_ARN" \
44-
-c user_role="$USER_ROLE_ARN"
45-
46-
cdk deploy SSM-Advanced-Tier-Stack \
41+
AWS_REGION="$REGION" cdk -a "$APP" deploy SSM-Advanced-Tier-Stack \
4742
-c sagemaker_role="$SAGEMAKER_ROLE_ARN" \
4843
-c user_role="$USER_ROLE_ARN"
4944
```
@@ -55,11 +50,9 @@ REGION=
5550
```
5651

5752
```shell
58-
cdk bootstrap aws://"$ACCOUNT_ID"/"$REGION" \
59-
-c sagemaker_role="$SAGEMAKER_ROLE_ARN" \
60-
-c user_role="$USER_ROLE_ARN"
53+
cdk bootstrap aws://"$ACCOUNT_ID"/"$REGION"
6154

62-
AWS_REGION="$REGION" cdk deploy SSM-Advanced-Tier-Stack \
55+
AWS_REGION="$REGION" cdk -a "$APP" deploy SSM-Advanced-Tier-Stack \
6356
-c sagemaker_role="$SAGEMAKER_ROLE_ARN" \
6457
-c user_role="$USER_ROLE_ARN"
6558
```

cdk/app.py

Lines changed: 0 additions & 15 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.

sagemaker_ssh_helper/cdk/app.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env python3
2+
import aws_cdk as cdk
3+
4+
from sagemaker_ssh_helper.cdk.cdk.cdk_stack import CdkStack
5+
from sagemaker_ssh_helper.cdk.iam_ssm.iam_ssm_stack import IamSsmStack
6+
from sagemaker_ssh_helper.cdk.iam_ssm.iam_ssm_stack_tests import IamSsmStackTests
7+
from sagemaker_ssh_helper.cdk.iam_ssm.ssm_advanced_tier_stack import SsmAdvancedTierStack
8+
9+
app = cdk.App()
10+
CdkStack(app, "CdkStack")
11+
IamSsmStack(app, "SSH-IAM-SSM-Stack")
12+
IamSsmStackTests(app, "SSH-IAM-SSM-Stack-Tests")
13+
SsmAdvancedTierStack(app, "SSM-Advanced-Tier-Stack")
14+
15+
app.synth()
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

sagemaker_ssh_helper/cdk/tests/unit/__init__.py

Whitespace-only changes.
Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import aws_cdk as core
22
import aws_cdk.assertions as assertions
3+
import pytest
4+
5+
from sagemaker_ssh_helper.cdk.cdk.cdk_stack import CdkStack
36

4-
from cdk.cdk_stack import CdkStack
57

68
# example tests. To run these tests, uncomment this file along with the example
79
# resource in cdk/cdk_stack.py
10+
@pytest.mark.manual
811
def test_sqs_queue_created():
912
app = core.App()
1013
stack = CdkStack(app, "cdk")
1114
template = assertions.Template.from_stack(stack)
1215

13-
# template.has_resource_properties("AWS::SQS::Queue", {
14-
# "VisibilityTimeout": 300
15-
# })
16+
template.has_resource_properties("AWS::SQS::Queue", {
17+
"VisibilityTimeout": 300
18+
})

tests/generate_sagemaker_config.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
mkdir -p /root/.config/sagemaker
4+
5+
cat > /root/.config/sagemaker/config.yaml <<EOF
6+
SchemaVersion: '1.0'
7+
SageMaker:
8+
TrainingJob:
9+
RoleArn: '$SAGEMAKER_ROLE'
10+
EOF

0 commit comments

Comments
 (0)