Skip to content

Commit

Permalink
Use dictionary literals, poetry & pyright in aws-py-fargate (#1656)
Browse files Browse the repository at this point in the history
Use the latest python features from
pulumi/docs#12123 in the aws-py-fargate example.

This could also go into a separate example instead of changing the
existing one, not sure what we prefer here?
  • Loading branch information
julienp committed Jul 3, 2024
2 parents aaacef9 + 84ddc8b commit ce94281
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 36 deletions.
4 changes: 2 additions & 2 deletions aws-py-fargate/Pulumi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ description: A container running in AWS ECS Fargate, using Python infrastructure
runtime:
name: python
options:
virtualenv: venv

toolchain: poetry
typechecker: pyright
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
12 changes: 12 additions & 0 deletions aws-py-fargate/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[tool.poetry]
package-mode = false

[tool.poetry.dependencies]
python = "^3.10"
pulumi = ">=3.122.0,<4.0.0"
pulumi-aws = ">=6.42.1,<7.0.0"
pyright = ">=1.1.369,<2.0.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
2 changes: 0 additions & 2 deletions aws-py-fargate/requirements.txt

This file was deleted.

0 comments on commit ce94281

Please sign in to comment.