> For the complete documentation index, see [llms.txt](https://omalab.gitbook.io/engineeringwiki/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://omalab.gitbook.io/engineeringwiki/working/s3.md).

# S3

## listing and deleting snapshots w/ certain descriptions (etc.)

```
# from console:
aws ec2 describe-snapshots 
>
 snapshots_state.json

# then irb:
require 'json'
f = File.read "snapshots_state.json"; nil
data = JSON.parse(f); nil
data['Snapshots'].select { |h| h['Description'] =~ /^Snapshot of PGDATA/ }.count
data['Snapshots'].select { |h| h['Description'] =~ /^Snapshot of PGDATA/ }.map { |h| h['VolumeSize'] }
ids = data['Snapshots'].select { |h| h['Description'] =~ /^Snapshot of PGDATA/ }.map { |h| h['SnapshotId'] }
File.open('snapshot_ids.txt','w') { |f| f.write ids.join("\n") }

# then, back to console
wc -l snapshot_ids.txt
cat snapshot_ids.txt | xargs -i aws ec2 delete-snapshot --snapshot-id {}
```
