Reputation: 5554
There is a command to create flow logs for a VPC in boto3:
client = session.client("ec2")
client.create_flow_logs(...)
This returns, among other things, flow log ID. Suppose that this ID is not saved by the user, and now the user wants to delete that created flow log. How does one do that?
client.delete_flow_logs takes as an argument the flow log IDs to delete, but how do you get those IDs?
client.describe_flow_logs also takes flow log IDs as an argument.
client.describe_vpcs does not return any information about flow logs.
What is the correct API to get the flow log IDs for a VPC, in order to delete them?
EDIT:
I tried the code below, and it does not return any flow log information either.
ec2 = boto3.resource("ec2")
vpc = ec2.Vpc(vpc_id)
vpc.load()
Upvotes: 1
Views: 2746
Reputation: 31
I realise that this question is quite old, but will post my answer for posterity.
To find out flow logs which are attached to the said VPC, you would use the client.describe_flow_logs
function instead, and add a filter for the specific VPC resource-id
.
Eg:
import boto3
client=boto3.client('ec2')
response=client.describe_flow_logs(
Filters=[
{
'Name' : 'resource-id',
'Values' : [ '<vpc-id>' ]
}
]
)
Upvotes: 3
Reputation: 16003
FlowLogIds
is an optional parameter of describe_flow_logs
which you would use when you want to get detailed information about specific flow logs. To list all your flow logs, omit that parameter.
Upvotes: 1