Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for other AWS partitions (cn, us-gov, etc.) #42

Merged
merged 3 commits into from
Apr 10, 2024
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- update MySQL instance to use T3 instance type
- upgrade `cdk_ecr_deployment` version to fix the deprecated `go1.x` lambda runtime
- add support for other AWS partitions

### **Removed**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export class SagemakerJumpStartFmEndpointStack extends cdk.Stack {
new PolicyStatement({
effect: Effect.ALLOW,
actions: ["s3:GetObject", "s3:ListBucket"],
resources: ["arn:aws:s3:::jumpstart-*"],
resources: [`arn:${this.partition}:s3:::jumpstart-*`],
}),
new PolicyStatement({
effect: Effect.ALLOW,
Expand Down
6 changes: 3 additions & 3 deletions modules/sagemaker/sagemaker-custom-kernel/modulestack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ Resources:
- "sagemaker:DescribeDomain"
- "sagemaker:UpdateDomain"
Resource:
- !Sub "arn:aws:sagemaker:${AWS::Region}:${AWS::AccountId}:domain/${StudioDomainId}"
- !Sub "arn:${AWS::Partition}:sagemaker:${AWS::Region}:${AWS::AccountId}:domain/${StudioDomainId}"
- Effect: Allow
Action:
- "iam:PassRole"
Resource:
- !Sub "arn:aws:iam::${AWS::AccountId}:role/${ProjectName}-${DeploymentName}-${ModuleName}-image-role"
- !Sub "arn:${AWS::Partition}:iam::${AWS::AccountId}:role/${ProjectName}-${DeploymentName}-${ModuleName}-image-role"
- !Ref StudioExecutionRoleArn
- Action:
- "ecr:*LayerUpload"
Expand All @@ -55,7 +55,7 @@ Resources:
- "ecr:UploadLayerPart"
Effect: Allow
Resource:
- !Sub "arn:aws:ecr:${AWS::Region}:${AWS::AccountId}:repository/${ECRRepoName}"
- !Sub "arn:${AWS::Partition}:ecr:${AWS::Region}:${AWS::AccountId}:repository/${ECRRepoName}"
Version: 2012-10-17
PolicyName: "mlops-modulespecific-policy"
Roles: [!Ref RoleName]
2 changes: 1 addition & 1 deletion modules/sagemaker/sagemaker-endpoint/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def __init__(
"kms:Decrypt",
"kms:DescribeKey",
],
resources=[f"arn:aws:kms:{self.region}:{self.account}:key/*"],
resources=[f"arn:{self.partition}:kms:{self.region}:{self.account}:key/*"],
),
)

Expand Down
20 changes: 10 additions & 10 deletions modules/sagemaker/sagemaker-studio/helper_constructs/sm_roles.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(
iam.PolicyStatement(
effect=iam.Effect.ALLOW,
actions=["iam:PassRole"],
resources=[f"arn:aws:iam::{Aws.ACCOUNT_ID}:role/cdk*"],
resources=[f"arn:{Aws.PARTITION}:iam::{Aws.ACCOUNT_ID}:role/cdk*"],
),
],
)
Expand Down Expand Up @@ -173,21 +173,21 @@ def __init__(
"s3:GetBucketLocation",
],
resources=[
"arn:aws:s3:::{}*/*".format(s3_bucket_prefix),
"arn:aws:s3:::{}*".format(s3_bucket_prefix),
"arn:aws:s3:::cdk*/*",
"arn:aws:s3:::cdk*",
"arn:aws:s3:::sagemaker*",
"arn:aws:s3:::sagemaker*/*",
f"arn:{Aws.PARTITION}:s3:::{s3_bucket_prefix}*/*",
f"arn:{Aws.PARTITION}:s3:::{s3_bucket_prefix}*",
f"arn:{Aws.PARTITION}:s3:::cdk*/*",
f"arn:{Aws.PARTITION}:s3:::cdk*",
f"arn:{Aws.PARTITION}:s3:::sagemaker*",
f"arn:{Aws.PARTITION}:s3:::sagemaker*/*",
],
),
iam.PolicyStatement(
effect=iam.Effect.ALLOW,
actions=["s3:ListBucket"],
resources=[
"arn:aws:s3:::{}*".format(s3_bucket_prefix),
"arn:aws:s3:::cdk*",
"arn:aws:s3:::sagemaker*",
f"arn:{Aws.PARTITION}:s3:::{s3_bucket_prefix}*",
f"arn:{Aws.PARTITION}:s3:::cdk*",
f"arn:{Aws.PARTITION}:s3:::sagemaker*",
],
),
iam.PolicyStatement(
Expand Down
4 changes: 2 additions & 2 deletions modules/sagemaker/sagemaker-studio/modulestack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ Resources:
- "elasticfilesystem:DeleteMountTarget"
- "elasticfilesystem:DeleteFileSystem"
Resource:
- !Sub "arn:aws:elasticfilesystem:${AWS::Region}:${AWS::AccountId}:file-system/*"
- !Sub "arn:aws:elasticfilesystem:${AWS::Region}:${AWS::AccountId}:access-point/*"
- !Sub "arn:${AWS::Partition}:elasticfilesystem:${AWS::Region}:${AWS::AccountId}:file-system/*"
- !Sub "arn:${AWS::Partition}:elasticfilesystem:${AWS::Region}:${AWS::AccountId}:access-point/*"
- Effect: Allow
Action:
- "elasticfilesystem:Describe*"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ def __init__(
"kms:DescribeKey",
],
effect=iam.Effect.ALLOW,
resources=[f"arn:aws:kms:{Aws.REGION}:{Aws.ACCOUNT_ID}:key/*"],
resources=[f"arn:{Aws.PARTITION}:kms:{Aws.REGION}:{Aws.ACCOUNT_ID}:key/*"],
),
]
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def __init__(
"kms:DescribeKey",
],
effect=iam.Effect.ALLOW,
resources=[f"arn:aws:kms:{Aws.REGION}:{Aws.ACCOUNT_ID}:key/*"],
resources=[f"arn:{Aws.PARTITION}:kms:{Aws.REGION}:{Aws.ACCOUNT_ID}:key/*"],
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def __init__(
"kms:DescribeKey",
],
effect=iam.Effect.ALLOW,
resources=[f"arn:aws:kms:{Aws.REGION}:{DEPLOYMENT_ACCOUNT}:key/*"],
resources=[f"arn:{Aws.PARTITION}:kms:{Aws.REGION}:{DEPLOYMENT_ACCOUNT}:key/*"],
),
]
),
Expand Down
60 changes: 30 additions & 30 deletions one-click-launch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Resources:
Service: codebuild.amazonaws.com

ManagedPolicyArns:
- arn:aws:iam::aws:policy/AWSCodeBuildAdminAccess
- !Sub arn:${AWS::Partition}:iam::aws:policy/AWSCodeBuildAdminAccess
Policies:
- PolicyName: create
PolicyDocument:
Expand All @@ -39,9 +39,9 @@ Resources:
- cloudformation:DeleteStack
- cloudformation:DeleteChangeSet
Resource:
- !Sub arn:aws:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/CDKToolkit/*
- !Sub arn:aws:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/seedfarmer-*
- !Sub arn:aws:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/aws-codeseeder-*
- !Sub arn:${AWS::Partition}:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/CDKToolkit/*
- !Sub arn:${AWS::Partition}:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/seedfarmer-*
- !Sub arn:${AWS::Partition}:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/aws-codeseeder-*
- Sid: IAM
Effect: Allow
Action:
Expand All @@ -55,8 +55,8 @@ Resources:
- iam:getRolePolicy
- iam:TagRole
Resource:
- !Sub arn:aws:iam::${AWS::AccountId}:role/cdk-*
- !Sub arn:aws:iam::${AWS::AccountId}:role/seedfarmer-*
- !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-*
- !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:role/seedfarmer-*
- Sid: ECR
Effect: Allow
Action:
Expand All @@ -67,7 +67,7 @@ Resources:
- ecr:PutLifecyclePolicy
- ecr:PutImageTagMutability
- ecr:List*
Resource: !Sub arn:aws:ecr:${AWS::Region}:${AWS::AccountId}:repository/cdk-*
Resource: !Sub arn:${AWS::Partition}:ecr:${AWS::Region}:${AWS::AccountId}:repository/cdk-*
- Sid: S3
Effect: Allow
Action:
Expand All @@ -91,14 +91,14 @@ Resources:
- ssm:PutParameter
- ssm:DeleteParameter
- ssm:GetParameters
Resource: !Sub arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/cdk-*
Resource: !Sub arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:parameter/cdk-*
- Sid: SecretsManager
Effect: Allow
Action:
- secretsmanager:CreateSecret
- secretsmanager:DeleteSecret
Resource:
- !Sub "arn:aws:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:*"
- !Sub "arn:${AWS::Partition}:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:*"
- Sid: Password
Effect: Allow
Action:
Expand All @@ -112,8 +112,8 @@ Resources:
- es:List*
- es:ESHttpGet
Resource:
- !Sub "arn:aws:es:${AWS::Region}:${AWS::AccountId}:*"
- !Sub "arn:aws:es:${AWS::Region}:${AWS::AccountId}:domain:*"
- !Sub "arn:${AWS::Partition}:es:${AWS::Region}:${AWS::AccountId}:*"
- !Sub "arn:${AWS::Partition}:es:${AWS::Region}:${AWS::AccountId}:domain:*"
- PolicyName: delete
PolicyDocument:
Version: "2012-10-17"
Expand All @@ -130,10 +130,10 @@ Resources:
- cloudformation:DeleteStack
- cloudformation:DeleteChangeSet
Resource:
- !Sub arn:aws:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/CDKToolkit/*
- !Sub arn:aws:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/seedfarmer-*
- !Sub arn:aws:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/aws-codeseeder-*
- !Sub arn:aws:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/mlops*
- !Sub arn:${AWS::Partition}:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/CDKToolkit/*
- !Sub arn:${AWS::Partition}:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/seedfarmer-*
- !Sub arn:${AWS::Partition}:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/aws-codeseeder-*
- !Sub arn:${AWS::Partition}:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/mlops*
- Sid: IAM
Effect: Allow
Action:
Expand All @@ -150,10 +150,10 @@ Resources:
- iam:List*
- iam:DeletePolicy
Resource:
- !Sub arn:aws:iam::${AWS::AccountId}:role/cdk-*
- !Sub arn:aws:iam::${AWS::AccountId}:role/seedfarmer-*
- !Sub arn:aws:iam::${AWS::AccountId}:role/codeseeder-*
- !Sub arn:aws:iam::${AWS::AccountId}:policy/codeseeder-*
- !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:role/cdk-*
- !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:role/seedfarmer-*
- !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:role/codeseeder-*
- !Sub arn:${AWS::Partition}:iam::${AWS::AccountId}:policy/codeseeder-*
- Sid: ECR
Effect: Allow
Action:
Expand All @@ -164,7 +164,7 @@ Resources:
- ecr:PutLifecyclePolicy
- ecr:PutImageTagMutability
- ecr:List*
Resource: !Sub arn:aws:ecr:${AWS::Region}:${AWS::AccountId}:repository/cdk-*
Resource: !Sub arn:${AWS::Partition}:ecr:${AWS::Region}:${AWS::AccountId}:repository/cdk-*
- Sid: S3KMS
Effect: Allow
Action:
Expand Down Expand Up @@ -194,14 +194,14 @@ Resources:
- ssm:PutParameter
- ssm:DeleteParameter
- ssm:GetParameters
Resource: !Sub arn:aws:ssm:${AWS::Region}:${AWS::AccountId}:parameter/cdk-*
Resource: !Sub arn:${AWS::Partition}:ssm:${AWS::Region}:${AWS::AccountId}:parameter/cdk-*
- Sid: SecretsManager
Effect: Allow
Action:
- secretsmanager:CreateSecret
- secretsmanager:DeleteSecret
Resource:
- !Sub "arn:aws:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:*"
- !Sub "arn:${AWS::Partition}:secretsmanager:${AWS::Region}:${AWS::AccountId}:secret:*"
- Sid: Password
Effect: Allow
Action:
Expand All @@ -215,25 +215,25 @@ Resources:
- es:List*
- es:ESHttpGet
Resource:
- !Sub "arn:aws:es:${AWS::Region}:${AWS::AccountId}:*"
- !Sub "arn:aws:es:${AWS::Region}:${AWS::AccountId}:domain:*"
- !Sub "arn:${AWS::Partition}:es:${AWS::Region}:${AWS::AccountId}:*"
- !Sub "arn:${AWS::Partition}:es:${AWS::Region}:${AWS::AccountId}:domain:*"
- Sid: S3DeleteCodeseeder
Effect: Allow
Action:
- s3:Delete*
- s3:PutObject
- s3:PutObjectAcl
Resource:
- !Sub "arn:aws:s3:::codeseeder-mlops-${AWS::AccountId}-*"
- !Sub "arn:aws:s3:::codeseeder-mlops-${AWS::AccountId}-*/*"
- "arn:aws:s3:::mlops*"
- "arn:aws:s3:::mlops*/*"
- !Sub "arn:${AWS::Partition}:s3:::codeseeder-mlops-${AWS::AccountId}-*"
- !Sub "arn:${AWS::Partition}:s3:::codeseeder-mlops-${AWS::AccountId}-*/*"
- !Sub "arn:${AWS::Partition}:s3:::mlops*"
- !Sub "arn:${AWS::Partition}:s3:::mlops*/*"
- Sid: CodebuildCleanup
Effect: Allow
Action:
- codebuild:DeleteProject
Resource:
- !Sub "arn:aws:codebuild:${AWS::Region}:${AWS::AccountId}:project/codeseeder-mlops"
- !Sub "arn:${AWS::Partition}:codebuild:${AWS::Region}:${AWS::AccountId}:project/codeseeder-mlops"
CreateUpdateCodeBuildProject:
Type: AWS::CodeBuild::Project
Properties:
Expand Down Expand Up @@ -472,4 +472,4 @@ Resources:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: arn:aws:logs:*:*:*
Resource: !Sub arn:${AWS::Partition}:logs:*:*:*
Loading