Esempio n. 1
0
// Retrieving an archive and a vault inventory are asynchronous operations in
// Amazon Glacier for which you must first initiate a job and wait for the job
// to complete before you can download the job output. Most Amazon Glacier jobs
// take about four hours to complete. So you can configure a vault to post a
// message to an Amazon Simple Notification Service (SNS) topic when these jobs
// complete. You can use this operation to set notification configuration on the
// vault.
//
// Amazon SNS topics must grant permission to the vault to be allowed to publish
// notifications to the topic.
//
// To configure vault notifications, send a request to the notification-
// configuration subresource of the vault. A notification configuration is
// specific to a vault; therefore, it is also referred to as a vault
// subresource.
func (c *Connection) SetVaultNotifications(name string, n *Notifications) error {
	// Build request.
	body, err := json.Marshal(n)
	if err != nil {
		return err
	}

	request, err := http.NewRequest("PUT", "https://"+c.Signature.Region.Glacier+"/-/vaults/"+name+
		"/notification-configuration", nil)
	if err != nil {
		return err
	}
	request.Header.Add("x-amz-glacier-version", "2012-06-01")

	c.Signature.Sign(request, aws.MemoryPayload(body))

	// Perform request.
	response, err := c.client().Do(request)
	if err != nil {
		return err
	}
	defer response.Body.Close()

	if response.StatusCode != http.StatusNoContent {
		return aws.ParseError(response)
	}

	io.Copy(ioutil.Discard, response.Body)

	// Parse success response.
	return nil
}
Esempio n. 2
0
// Initiate an vault inventory job with the vault name. You can also provide
// an optional job description when you initiate these jobs. If you specify a
// topic, Amazon Glacier sends notifications to both the supplied topic and
// the vault's ArchiveRetrievalCompleted notification topic.
//
// Returns the job ID or the first error encountered.
func (c *Connection) InitiateInventoryJob(vault, topic, description string) (string, error) {
	// Build request.
	j := jobRequest{Type: "inventory-retrieval", Description: description, SNSTopic: topic}
	body, _ := json.Marshal(j)

	request, err := http.NewRequest("POST", c.vault(vault)+"/jobs", nil)
	if err != nil {
		return "", err
	}
	request.Header.Add("x-amz-glacier-version", "2012-06-01")

	c.Signature.Sign(request, aws.MemoryPayload(body))

	// Perform request.
	response, err := c.client().Do(request)
	if err != nil {
		return "", err
	}
	defer response.Body.Close()

	if response.StatusCode != http.StatusAccepted {
		return "", aws.ParseError(response)
	}

	io.Copy(ioutil.Discard, response.Body)

	// Parse success response.
	return response.Header.Get("x-amz-job-id"), nil
}