Skip to content

Instantly share code, notes, and snippets.

@jaxxstorm
Created April 20, 2023 21:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaxxstorm/bc1318bb6db5dbbec443390706748bff to your computer and use it in GitHub Desktop.
Save jaxxstorm/bc1318bb6db5dbbec443390706748bff to your computer and use it in GitHub Desktop.
Get ENI IDs from a fargate task in python
# private IP
# we created the security group, so we use that to retrieve the ENI addresses.
# this like returns one per subnet associated with the fargate task
eni = aws.ec2.get_network_interfaces_output(
filters=[{
"name": "group-id",
"values": [ group.id ],
}],
)
# define a function that looks up IPs from a list of ENI IDs
def get_private_ip(ids: str) -> list[str]:
private_ips: list[str] = []
for count, id in enumerate(ids):
eni = aws.ec2.get_network_interface(id=id)
private_ips.append(eni.private_ip)
return private_ips
# we need to wait for the ENI results to return from the API,
# so inside an apply, we loop through the values and then retrieve the private IP
private_ips = eni.ids.apply(
lambda ids: get_private_ip(ids)
)
pulumi.export("private_ips", private_ips)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment