Skip to content

Commit

Permalink
Use dictionary literals in aws-py-fargate
Browse files Browse the repository at this point in the history
  • Loading branch information
julienp committed Jul 2, 2024
1 parent a8f0691 commit 84ddc8b
Showing 1 changed file with 30 additions and 32 deletions.
62 changes: 30 additions & 32 deletions aws-py-fargate/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,28 @@
# Read back the default VPC and public subnets, which we will use.
default_vpc = aws.ec2.get_vpc(default=True)
default_vpc_subnets = aws.ec2.get_subnets(
filters = [
aws.ec2.GetSubnetsFilterArgs(
name='vpc-id',
values=[default_vpc.id],
),
],
filters = [{
'name': 'vpc-id',
'values': [default_vpc.id],
}],
)

# Create a SecurityGroup that permits HTTP ingress and unrestricted egress.
group = aws.ec2.SecurityGroup('web-secgrp',
vpc_id=default_vpc.id,
description='Enable HTTP access',
ingress=[aws.ec2.SecurityGroupIngressArgs(
protocol='tcp',
from_port=80,
to_port=80,
cidr_blocks=['0.0.0.0/0'],
)],
egress=[aws.ec2.SecurityGroupEgressArgs(
protocol='-1',
from_port=0,
to_port=0,
cidr_blocks=['0.0.0.0/0'],
)],
ingress=[{
'protocol': 'tcp',
'from_port': 80,
'to_port': 80,
'cidr_blocks': ['0.0.0.0/0'],
}],
egress=[{
'protocol': '-1',
'from_port': 0,
'to_port': 0,
'cidr_blocks': ['0.0.0.0/0'],
}],
)

# Create a load balancer to listen for HTTP traffic on port 80.
Expand All @@ -50,10 +48,10 @@
wl = aws.lb.Listener('web',
load_balancer_arn=alb.arn,
port=80,
default_actions=[aws.lb.ListenerDefaultActionArgs(
type='forward',
target_group_arn=atg.arn,
)],
default_actions=[{
'type': 'forward',
'target_group_arn': atg.arn,
}],
)

# Create an IAM role that can be used by our service's task.
Expand Down Expand Up @@ -100,16 +98,16 @@
desired_count=3,
launch_type='FARGATE',
task_definition=task_definition.arn,
network_configuration=aws.ecs.ServiceNetworkConfigurationArgs(
assign_public_ip=True,
subnets=default_vpc_subnets.ids,
security_groups=[group.id],
),
load_balancers=[aws.ecs.ServiceLoadBalancerArgs(
target_group_arn=atg.arn,
container_name='my-app',
container_port=80,
)],
network_configuration={
'assign_public_ip': True,
'subnets': default_vpc_subnets.ids,
'security_groups': [group.id],
},
load_balancers=[{
'target_group_arn': atg.arn,
'container_name': 'my-app',
'container_port': 80,
}],
opts=ResourceOptions(depends_on=[wl]),
)

Expand Down

0 comments on commit 84ddc8b

Please sign in to comment.