'How can I get the VolumeId even when the EC2 instance is terminated?

I'm using EventBridge to execute lambda triggered by DetachVolume.

In this case, when terminateing EC2, Lamba processing(create tag for EBS based on VolumeID) cannot be performed on the additionally attached EBS.
This is because the request parameter of TerminateInstances is only instanceId and does not include VolumeID.

 {
  "source": ["aws.ec2"],
  "detail-type": ["AWS API Call via CloudTrail"],
  "detail": {
    "eventSource": ["ec2.amazonaws.com"],
    "eventName": ["DetachVolume","TerminateInstances"]
  }
}

How can I get the volumeid even when the EC2 instance is terminated?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source