Created
April 20, 2023 21:12
-
-
Save jaxxstorm/bc1318bb6db5dbbec443390706748bff to your computer and use it in GitHub Desktop.
Get ENI IDs from a fargate task in python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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