Search code examples
powershellamazon-web-servicesaws-powershell

Adding tags to ec2-Snapshots via powershell


I am trying to add tags to snapshots within AWS EC2 environment using powershell so that i can tag them for use down the road and some graduated snapshot retention.

I can manually create them through the console but for the life of me cannot find out which cmdlet to use. The best I've able to manage is edit-ec2snapshotattribute but that does not appear to be what I want.
I would rather not use the 'description' if possible during the creation of the snapshot as that is being used for other items


Solution

  • The cmdlet New-EC2Tag can be used to create new tags for any EC2 resource, including snapshots.

    Example:

    # Create a new tag with Key "Environment" and Value "Dev"
    PS C:\> New-EC2Tag -Resources "snap-1a2b3c4d" -Tags @{ Key="Environment"; Value = "Dev" }
    
    # View the newly created tag on the snapshot
    PS C:\> Get-EC2Snapshot -SnapshotIds "snap-1a2b3c4d" | % { $_.Tags }
    
    Key                                                         Value
    ---                                                         -----
    Environment                                                 Dev
    

    Documentation: