-
-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathapp.py
More file actions
49 lines (39 loc) · 1.52 KB
/
Copy pathapp.py
File metadata and controls
49 lines (39 loc) · 1.52 KB
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
#!/usr/bin/env python3
"""
Example: Grant IAM permissions to runners.
This example demonstrates how to grant AWS IAM permissions to runners,
allowing them to access AWS services like S3 buckets.
"""
import aws_cdk as cdk
from aws_cdk import Stack, aws_s3 as s3
from cloudsnorkel.cdk_github_runners import (
GitHubRunners,
CodeBuildRunnerProvider,
)
class IamPermissionsStack(Stack):
def __init__(self, scope, construct_id, **kwargs):
super().__init__(scope, construct_id, **kwargs)
# Create an S3 bucket for artifacts
artifacts_bucket = s3.Bucket(
self, "ArtifactsBucket",
encryption=s3.BucketEncryption.S3_MANAGED,
block_public_access=s3.BlockPublicAccess.BLOCK_ALL
)
# Create a CodeBuild provider
codebuild_provider = CodeBuildRunnerProvider(
self, "CodeBuildProvider",
labels=["codebuild", "linux", "x64"]
)
# Grant read/write permissions to the provider
# The provider will pass these permissions to all runners it creates.
# IMPORTANT: Any job/workflow that runs on these runners will have these permissions.
# Only grant the minimum permissions necessary for your use case.
artifacts_bucket.grant_read_write(codebuild_provider)
# Create the GitHub runners infrastructure
GitHubRunners(
self, "GitHubRunners",
providers=[codebuild_provider]
)
app = cdk.App()
IamPermissionsStack(app, "iam-permissions-example")
app.synth()