AWS Storage Gateway User Guide
Deleting Snapshots
]
},
{
"Sid": "StmtSgwListVolumes",
"Effect": "Allow",
"Action": [
"storagegateway:ListVolumes"
],
"Resource": [
"*"
]
}
]
}
The following C# code finds all snapshots in the specified gateway that match the volumes and the
specified cut-off period and then deletes them.
using System;
using System.Collections.Generic;
using System.Text;
using Amazon.EC2;
using Amazon.EC2.Model;
using Amazon.StorageGateway.Model;
using Amazon.StorageGateway;
namespace DeleteStorageGatewaySnapshotNS
{
class Program
{
/*
* Replace the variables below to match your environment.
*/
/* IAM AccessKey */
static String AwsAccessKey = "AKIA................";
/* IAM SecretKey */
static String AwsSecretKey = "***********************";
/* AWS Account number, 12 digits, no hyphen */
static String OwnerID = "123456789012";
/* Your Gateway ARN. Use a Storage Gateway ID, sgw-XXXXXXXX* */
static String GatewayARN = "arn:aws:storagegateway:ap-
southeast-2:123456789012:gateway/sgw-XXXXXXXX";
/* Snapshot status: "completed", "pending", "error" */
static String SnapshotStatus = "completed";
/* AWS Region where your gateway is activated */
static String AwsRegion = "ap-southeast-2";
/* Minimum age of snapshots before they are deleted (retention policy) */
static int daysBack = 30;
/*
* Do not modify the four lines below.
*/
static AmazonEC2Config ec2Config;
static AmazonEC2Client ec2Client;
static AmazonStorageGatewayClient sgClient;
static AmazonStorageGatewayConfig sgConfig;
API Version 2013-06-30
167