Skip to content

Instantly share code, notes, and snippets.

@josjaf
Created August 15, 2019 21:39
Show Gist options
  • Save josjaf/4efc1049f24612209fd5d74f7955ffb4 to your computer and use it in GitHub Desktop.
Save josjaf/4efc1049f24612209fd5d74f7955ffb4 to your computer and use it in GitHub Desktop.
from aws_cdk import (
aws_iam as aws_iam,
aws_s3 as aws_s3,
aws_ecr,
aws_codebuild,
aws_codepipeline,
aws_codepipeline_actions,
aws_s3,
core,
)
class Pipeline(core.Stack):
def __init__(self, app: core.App, id: str, shared_params: dict, shared_outputs: dict) -> None:
super().__init__(app, id)
codepipeline_role = aws_iam.Role(
self, "CodepipelineRole",
assumed_by=aws_iam.CompositePrincipal(
aws_iam.ServicePrincipal('codepipeline.amazonaws.com'),
aws_iam.AccountRootPrincipal()
),
max_session_duration=core.Duration.hours(1),
managed_policies=[aws_iam.ManagedPolicy.from_aws_managed_policy_name('AdministratorAccess')],
)
shared_outputs['bucket_obj'].grant_read_write(codepipeline_role)
policy = aws_iam.Policy(
self, "codepipelinerolepolicies",
policy_name='cdk',
statements=[
aws_iam.PolicyStatement(
effect=aws_iam.Effect.ALLOW,
actions=['codebuild:*'],
resources=['*']
),
aws_iam.PolicyStatement(
effect=aws_iam.Effect.ALLOW,
actions=[
's3:*',
],
resources=[shared_outputs['bucket_obj'].bucket_arn]
)
],
roles=[
codepipeline_role
]
)
source_output = aws_codepipeline.Artifact(artifact_name='source')
#source_output = aws_codepipeline.Artifact()
print(shared_outputs['bucket_obj'].bucket_arn)
pipeline = aws_codepipeline.Pipeline(
self,
"Pipeline",
pipeline_name='test',
artifact_bucket=shared_outputs['bucket_obj'],
role=codepipeline_role,
stages=[
aws_codepipeline.StageProps(
stage_name='Source',
actions=[aws_codepipeline_actions.S3SourceAction(
bucket=shared_outputs['bucket_obj'],
bucket_key='source.zip',
action_name='S3Source',
run_order=1,
output=source_output,
role=codepipeline_role
)
]
),
aws_codepipeline.StageProps(
stage_name='Build',
actions=[aws_codepipeline_actions.CodeBuildAction(
action_name='DockerBuildImages',
role=codepipeline_role,
input=source_output,
project=shared_outputs['codebuild_project_docker_build'],
run_order=1,
)
]
)
]
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment