def step_impl(ctx, bucket_name): sts = session.client('sts') cf = session.client('cloudfront') # account = sts.get_caller_identity()['Account'] region_name = sts.meta.region_name resp = cf.list_distributions() ctx.default_domain_name = f"{bucket_name}.s3-website-{region_name}.amazonaws.com" founds = list(filter(lambda v: v['Origins']['Items'][0]['DomainName'] == ctx.default_domain_name, resp['DistributionList']['Items'])) ctx.distribution = founds and founds[0] ctx.origins = { item['Id']: item for item in ctx.distribution['Origins']['Items'] }
def step_impl(ctx, subnet_count): ec2 = session.client('ec2') resp = ec2.describe_subnets( Filters=[{'Name': 'vpc-id', 'Values': [ctx.vpc['VpcId']]}] ) ctx.subnets = resp['Subnets'] assert len(resp['Subnets']) == int(subnet_count)
def step_impl(ctx, vpc_name): ec2 = session.client('ec2') for vpc in ec2.describe_vpcs()['Vpcs']: if tag_value(vpc, 'Name') == vpc_name: ctx.vpc = vpc break assert ctx.vpc
def step_impl(ctx, cluster_name): ecs = session.client('ecs') resp = ecs.list_clusters() arns = list(filter(lambda v: v.find(cluster_name) >= 0, resp['clusterArns'])) arn = arns[0] if arns else None resp = ecs.describe_clusters(clusters=[arn]) ctx.cluster = resp['clusters'][0]
def step_impl(ctx, cidr1, cidr2): ec2 = session.client('ec2') resp = ec2.describe_subnets( Filters=[ {'Name': 'vpc-id', 'Values': [ctx.vpc['VpcId']]}, ] ) subnets = list(filter(lambda v: tag_value(v, 'aws-cdk:subnet-type') == ctx.subnet_type, resp['Subnets'])) ctx.subnets = subnets assert sorted([v['CidrBlock'] for v in subnets]) == [cidr1, cidr2]
def step_impl(ctx, sid): iam = session.client('iam') assert 'taskRoleArn' in ctx.task_def role_name = ctx.task_def['taskRoleArn'].split('/')[-1] resp = iam.list_role_policies(RoleName=role_name) policy_name = resp['PolicyNames'][0] policy = iam.get_role_policy(RoleName=role_name, PolicyName=policy_name) ctx.policy = policy assert ctx.policy['PolicyDocument']['Statement'][0]['Sid'] == sid
def step_impl(ctx, service_name): ecs = session.client('ecs') resp = ecs.list_services(cluster=ctx.cluster['clusterArn']) arns = list(filter(lambda v: v.find(service_name) >= 0, resp['serviceArns'])) service_arn = arns[0] if arns else None resp = ecs.describe_services( cluster=ctx.cluster['clusterName'], services=[service_arn.split('/')[-1]] ) ctx.service = resp['services'][0]
def step_impl(ctx): iam = session.client('iam') resp = iam.list_roles() founds = list( filter(lambda v: v['RoleName'].startswith('Infra-ApiBuild'), resp['Roles'])) role_name = founds and founds[0]['RoleName'] resp = iam.list_role_policies(RoleName=role_name) policy_name = resp['PolicyNames'][0] ctx.policy = iam.get_role_policy(RoleName=role_name, PolicyName=policy_name) action = None for stat in ctx.policy['PolicyDocument']['Statement']: _action = stat['Action'] if _action[0].startswith('ecr:'): action = _action break assert action == [ "ecr:GetAuthorizationToken", "ecr:InitiateLayerUpload", "ecr:UploadLayerPart", "ecr:CompleteLayerUpload", "ecr:BatchCheckLayerAvailability", "ecr:PutImage" ]
def step_impl(ctx): ecs = session.client('ecs') task_def_name = ctx.service['taskDefinition'] assert len(list(filter(lambda v: v['taskDefinition'] == task_def_name, ctx.service['deployments']))) > 0 resp = ecs.describe_task_definition(taskDefinition=task_def_name) ctx.task_def = resp['taskDefinition']
def step_impl(ctx, pipeline_name): pipeline = session.client('codepipeline') resp = pipeline.get_pipeline(name=pipeline_name) ctx.pipeline = resp['pipeline'] assert ctx.pipeline['name'] == pipeline_name