// The AWS Lambda service creates ENIs behind the scenes and keeps these around for a while
// which would prevent SGs attached to such ENIs from being destroyed
The AWS Lambda service creates ENIs behind the scenes and keeps these around for a while
which would prevent SGs attached to such ENIs from being destroyed
// The AWS Lambda service creates ENIs behind the scenes and keeps these around for a while // which would prevent SGs attached to such ENIs from being destroyed
func deleteLingeringLambdaENIs(conn *ec2.EC2, filterName, resourceId string, timeout time.Duration) error {
	if minimumTimeout := 45 * time.Minute; timeout < minimumTimeout {
		timeout = minimumTimeout
	}
	resp, err := conn.DescribeNetworkInterfaces(&ec2.DescribeNetworkInterfacesInput{
		Filters: buildEC2AttributeFilterList(map[string]string{
			filterName:    resourceId,
			"description": "AWS Lambda VPC ENI*",
		}),
	})
	if err != nil {
		return fmt.Errorf("error describing ENIs: %s", err)
	}
	for _, eni := range resp.NetworkInterfaces {
		eniId := aws.StringValue(eni.NetworkInterfaceId)
		if eni.Attachment != nil && aws.StringValue(eni.Attachment.InstanceOwnerId) == "amazon-aws" {
			stateConf := &resource.StateChangeConf{
				Pending: []string{
					ec2.NetworkInterfaceStatusInUse,
				},
				Target: []string{
					ec2.NetworkInterfaceStatusAvailable,
				},
				Refresh:    networkInterfaceStateRefresh(conn, eniId),
				Timeout:    timeout,
				Delay:      10 * time.Second,
				MinTimeout: 10 * time.Second,
				ContinuousTargetOccurence: 18,
				NotFoundChecks:            1,
			}
			eniRaw, err := stateConf.WaitForState()
			if isResourceNotFoundError(err) {
				continue
			}
			if err != nil {
				return fmt.Errorf("error waiting for Lambda V2N ENI (%s) to become available for detachment: %s", eniId, err)
			}
			eni = eniRaw.(*ec2.NetworkInterface)
		}
		err = detachNetworkInterface(conn, eni, timeout)
		if err != nil {
			return fmt.Errorf("error detaching Lambda ENI (%s): %s", eniId, err)
		}
		err = deleteNetworkInterface(conn, eniId)
		if err != nil {
			return fmt.Errorf("error deleting Lambda ENI (%s): %s", eniId, err)
		}
	}
	return nil
}
func deleteLingeringLambdaENIs ( conn * ec2 . EC2 , filterName , resourceId string , timeout time . Duration ) error { if minimumTimeout := 45 * time . Minute ; timeout < minimumTimeout { timeout = minimumTimeout } resp , err := conn . DescribeNetworkInterfaces ( & ec2 . DescribeNetworkInterfacesInput { Filters : buildEC2AttributeFilterList ( map [ string ] string { filterName : resourceId , " " : " " , } ) , } ) if err != nil { return fmt . Errorf ( " " , err ) } for _ , eni := range resp . NetworkInterfaces { eniId := aws . StringValue ( eni . NetworkInterfaceId ) if eni . Attachment != nil && aws . StringValue ( eni . Attachment . InstanceOwnerId ) == " " { stateConf := & resource . StateChangeConf { Pending : [ ] string { ec2 . NetworkInterfaceStatusInUse , } , Target : [ ] string { ec2 . NetworkInterfaceStatusAvailable , } , Refresh : networkInterfaceStateRefresh ( conn , eniId ) , Timeout : timeout , Delay : 10 * time . Second , MinTimeout : 10 * time . Second , ContinuousTargetOccurence : 18 , NotFoundChecks : 1 , } eniRaw , err := stateConf . WaitForState ( ) if isResourceNotFoundError ( err ) { continue } if err != nil { return fmt . Errorf ( " " , eniId , err ) } eni = eniRaw . ( * ec2 . NetworkInterface ) } err = detachNetworkInterface ( conn , eni , timeout ) if err != nil { return fmt . Errorf ( " " , eniId , err ) } err = deleteNetworkInterface ( conn , eniId ) if err != nil { return fmt . Errorf ( " " , eniId , err ) } } return nil }
The AWS Lambda service creates ENIs behind the scenes and keeps these around for a while
which would prevent SGs attached to such ENIs from being destroyed
The AWS Lambda service creates ENIs behind the scenes and keeps these around for a while which would prevent SGs attached to such ENIs from being destroyed
// AWS Lambda service team confirms P99 deletion time of ~35 minutes. Buffer for safety. // Hyperplane attached ENI. // Wait for it to be moved into a removable state. // Handle EC2 ENI eventual consistency. It can take up to 3 minutes.