forked from brightsparc/amazon-sagemaker-drift-detection
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgithub-actions-setup.yml
81 lines (74 loc) · 2.24 KB
/
github-actions-setup.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
AWSTemplateFormatVersion: "2010-09-09"
Description: Setup IAM user for GitHub Actions and IAM role for SageMaker
Parameters:
GitHubActionsUserName:
Type: String
Default: github-actions-sagemaker-user
SageMakerRoleName:
Type: String
Default: github-actions-sagemaker-role
Resources:
GitHubActionsUser:
Type: AWS::IAM::User
Properties:
UserName: !Ref GitHubActionsUserName
GitHubActionsUserAccessKey:
Type: AWS::IAM::AccessKey
Properties:
UserName: !Ref GitHubActionsUser
Serial: 1
GitHubActionsCredentials:
Type: AWS::SecretsManager::Secret
Properties:
Name: !Ref GitHubActionsUserName
SecretString: !Sub |
{
"AccessKeyId":"${GitHubActionsUserAccessKey}",
"SecretAccessKey":"${GitHubActionsUserAccessKey.SecretAccessKey}"
}
# Permissions to perform cloudformation and assume pass SageMakerRole for autoscaling
GitHubActionsDeployPolicy:
Type: AWS::IAM::Policy
Properties:
Roles:
- !Ref SageMakerRole
PolicyName: allow-github-actions-cloudformation-deploy
PolicyDocument:
Version: "2012-10-17"
Statement:
- Action:
- "cloudformation:*"
Effect: Allow
Resource: "*"
- Action: "cloudformation:DeleteStack"
Effect: Deny
Resource: "*"
- Action: "iam:PassRole"
Effect: Allow
Resource: !GetAtt SageMakerRole.Arn
SageMakerRole:
Type: AWS::IAM::Role
Properties:
RoleName: !Ref SageMakerRoleName
MaxSessionDuration: 43200 # 12 hours maximum duration
AssumeRolePolicyDocument:
Version: "2012-10-17"
Statement:
- Effect: "Allow"
Principal:
Service:
- sagemaker.amazonaws.com
Action:
- "sts:AssumeRole"
- Effect: "Allow"
Principal:
AWS: !GetAtt GitHubActionsUser.Arn
Action:
- "sts:AssumeRole"
- "sts:TagSession"
ManagedPolicyArns:
- arn:aws:iam::aws:policy/AmazonS3FullAccess
- arn:aws:iam::aws:policy/AmazonSageMakerFullAccess
Outputs:
SageMakerRoleArn:
Value: !GetAtt SageMakerRole.Arn