func ExampleElastiCache_DescribeEvents() {
	svc := elasticache.New(nil)

	params := &elasticache.DescribeEventsInput{
		Duration:         aws.Long(1),
		EndTime:          aws.Time(time.Now()),
		Marker:           aws.String("String"),
		MaxRecords:       aws.Long(1),
		SourceIdentifier: aws.String("String"),
		SourceType:       aws.String("SourceType"),
		StartTime:        aws.Time(time.Now()),
	}
	resp, err := svc.DescribeEvents(params)

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			// Generic AWS Error with Code, Message, and original error (if any)
			fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				// A service error occurred
				fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			// This case should never be hit, The SDK should alwsy return an
			// error which satisfies the awserr.Error interface.
			fmt.Println(err.Error())
		}
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
func ExampleConfigService_GetResourceConfigHistory() {
	svc := configservice.New(nil)

	params := &configservice.GetResourceConfigHistoryInput{
		ResourceID:         aws.String("ResourceId"),   // Required
		ResourceType:       aws.String("ResourceType"), // Required
		ChronologicalOrder: aws.String("ChronologicalOrder"),
		EarlierTime:        aws.Time(time.Now()),
		LaterTime:          aws.Time(time.Now()),
		Limit:              aws.Long(1),
		NextToken:          aws.String("NextToken"),
	}
	resp, err := svc.GetResourceConfigHistory(params)

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			// Generic AWS Error with Code, Message, and original error (if any)
			fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				// A service error occurred
				fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			// This case should never be hit, The SDK should alwsy return an
			// error which satisfies the awserr.Error interface.
			fmt.Println(err.Error())
		}
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Beispiel #3
0
func ExampleAutoScaling_DescribeScheduledActions() {
	svc := autoscaling.New(nil)

	params := &autoscaling.DescribeScheduledActionsInput{
		AutoScalingGroupName: aws.String("ResourceName"),
		EndTime:              aws.Time(time.Now()),
		MaxRecords:           aws.Long(1),
		NextToken:            aws.String("XmlString"),
		ScheduledActionNames: []*string{
			aws.String("ResourceName"), // Required
			// More values...
		},
		StartTime: aws.Time(time.Now()),
	}
	resp, err := svc.DescribeScheduledActions(params)

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			// Generic AWS Error with Code, Message, and original error (if any)
			fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				// A service error occurred
				fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			// This case should never be hit, The SDK should alwsy return an
			// error which satisfies the awserr.Error interface.
			fmt.Println(err.Error())
		}
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
func ExampleEMR_ListClusters() {
	svc := emr.New(nil)

	params := &emr.ListClustersInput{
		ClusterStates: []*string{
			aws.String("ClusterState"), // Required
			// More values...
		},
		CreatedAfter:  aws.Time(time.Now()),
		CreatedBefore: aws.Time(time.Now()),
		Marker:        aws.String("Marker"),
	}
	resp, err := svc.ListClusters(params)

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			// Generic AWS Error with Code, Message, and original error (if any)
			fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				// A service error occurred
				fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			// This case should never be hit, The SDK should alwsy return an
			// error which satisfies the awserr.Error interface.
			fmt.Println(err.Error())
		}
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Beispiel #5
0
func ExampleS3_HeadObject() {
	svc := s3.New(nil)

	params := &s3.HeadObjectInput{
		Bucket:               aws.String("BucketName"), // Required
		Key:                  aws.String("ObjectKey"),  // Required
		IfMatch:              aws.String("IfMatch"),
		IfModifiedSince:      aws.Time(time.Now()),
		IfNoneMatch:          aws.String("IfNoneMatch"),
		IfUnmodifiedSince:    aws.Time(time.Now()),
		Range:                aws.String("Range"),
		RequestPayer:         aws.String("RequestPayer"),
		SSECustomerAlgorithm: aws.String("SSECustomerAlgorithm"),
		SSECustomerKey:       aws.String("SSECustomerKey"),
		SSECustomerKeyMD5:    aws.String("SSECustomerKeyMD5"),
		VersionID:            aws.String("ObjectVersionId"),
	}
	resp, err := svc.HeadObject(params)

	if awserr := aws.Error(err); awserr != nil {
		// A service error occurred.
		fmt.Println("Error:", awserr.Code, awserr.Message)
	} else if err != nil {
		// A non-service error occurred.
		panic(err)
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Beispiel #6
0
func ExampleS3_UploadPartCopy() {
	svc := s3.New(nil)

	params := &s3.UploadPartCopyInput{
		Bucket:                         aws.String("BucketName"),        // Required
		CopySource:                     aws.String("CopySource"),        // Required
		Key:                            aws.String("ObjectKey"),         // Required
		PartNumber:                     aws.Long(1),                     // Required
		UploadID:                       aws.String("MultipartUploadId"), // Required
		CopySourceIfMatch:              aws.String("CopySourceIfMatch"),
		CopySourceIfModifiedSince:      aws.Time(time.Now()),
		CopySourceIfNoneMatch:          aws.String("CopySourceIfNoneMatch"),
		CopySourceIfUnmodifiedSince:    aws.Time(time.Now()),
		CopySourceRange:                aws.String("CopySourceRange"),
		CopySourceSSECustomerAlgorithm: aws.String("CopySourceSSECustomerAlgorithm"),
		CopySourceSSECustomerKey:       aws.String("CopySourceSSECustomerKey"),
		CopySourceSSECustomerKeyMD5:    aws.String("CopySourceSSECustomerKeyMD5"),
		RequestPayer:                   aws.String("RequestPayer"),
		SSECustomerAlgorithm:           aws.String("SSECustomerAlgorithm"),
		SSECustomerKey:                 aws.String("SSECustomerKey"),
		SSECustomerKeyMD5:              aws.String("SSECustomerKeyMD5"),
	}
	resp, err := svc.UploadPartCopy(params)

	if awserr := aws.Error(err); awserr != nil {
		// A service error occurred.
		fmt.Println("Error:", awserr.Code, awserr.Message)
	} else if err != nil {
		// A non-service error occurred.
		panic(err)
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Beispiel #7
0
func ExampleAutoScaling_PutScheduledUpdateGroupAction() {
	svc := autoscaling.New(nil)

	params := &autoscaling.PutScheduledUpdateGroupActionInput{
		AutoScalingGroupName: aws.String("ResourceName"),       // Required
		ScheduledActionName:  aws.String("XmlStringMaxLen255"), // Required
		DesiredCapacity:      aws.Long(1),
		EndTime:              aws.Time(time.Now()),
		MaxSize:              aws.Long(1),
		MinSize:              aws.Long(1),
		Recurrence:           aws.String("XmlStringMaxLen255"),
		StartTime:            aws.Time(time.Now()),
		Time:                 aws.Time(time.Now()),
	}
	resp, err := svc.PutScheduledUpdateGroupAction(params)

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			// Generic AWS Error with Code, Message, and original error (if any)
			fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				// A service error occurred
				fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			// This case should never be hit, The SDK should alwsy return an
			// error which satisfies the awserr.Error interface.
			fmt.Println(err.Error())
		}
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
func ExampleCloudWatch_DescribeAlarmHistory() {
	svc := cloudwatch.New(nil)

	params := &cloudwatch.DescribeAlarmHistoryInput{
		AlarmName:       aws.String("AlarmName"),
		EndDate:         aws.Time(time.Now()),
		HistoryItemType: aws.String("HistoryItemType"),
		MaxRecords:      aws.Long(1),
		NextToken:       aws.String("NextToken"),
		StartDate:       aws.Time(time.Now()),
	}
	resp, err := svc.DescribeAlarmHistory(params)

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			// Generic AWS Error with Code, Message, and original error (if any)
			fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				// A service error occurred
				fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			// This case should never be hit, The SDK should alwsy return an
			// error which satisfies the awserr.Error interface.
			fmt.Println(err.Error())
		}
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Beispiel #9
0
func ExampleS3_CopyObject() {
	svc := s3.New(nil)

	params := &s3.CopyObjectInput{
		Bucket:                         aws.String("BucketName"), // Required
		CopySource:                     aws.String("CopySource"), // Required
		Key:                            aws.String("ObjectKey"),  // Required
		ACL:                            aws.String("ObjectCannedACL"),
		CacheControl:                   aws.String("CacheControl"),
		ContentDisposition:             aws.String("ContentDisposition"),
		ContentEncoding:                aws.String("ContentEncoding"),
		ContentLanguage:                aws.String("ContentLanguage"),
		ContentType:                    aws.String("ContentType"),
		CopySourceIfMatch:              aws.String("CopySourceIfMatch"),
		CopySourceIfModifiedSince:      aws.Time(time.Now()),
		CopySourceIfNoneMatch:          aws.String("CopySourceIfNoneMatch"),
		CopySourceIfUnmodifiedSince:    aws.Time(time.Now()),
		CopySourceSSECustomerAlgorithm: aws.String("CopySourceSSECustomerAlgorithm"),
		CopySourceSSECustomerKey:       aws.String("CopySourceSSECustomerKey"),
		CopySourceSSECustomerKeyMD5:    aws.String("CopySourceSSECustomerKeyMD5"),
		Expires:                        aws.Time(time.Now()),
		GrantFullControl:               aws.String("GrantFullControl"),
		GrantRead:                      aws.String("GrantRead"),
		GrantReadACP:                   aws.String("GrantReadACP"),
		GrantWriteACP:                  aws.String("GrantWriteACP"),
		Metadata: &map[string]*string{
			"Key": aws.String("MetadataValue"), // Required
			// More values...
		},
		MetadataDirective:       aws.String("MetadataDirective"),
		RequestPayer:            aws.String("RequestPayer"),
		SSECustomerAlgorithm:    aws.String("SSECustomerAlgorithm"),
		SSECustomerKey:          aws.String("SSECustomerKey"),
		SSECustomerKeyMD5:       aws.String("SSECustomerKeyMD5"),
		SSEKMSKeyID:             aws.String("SSEKMSKeyId"),
		ServerSideEncryption:    aws.String("ServerSideEncryption"),
		StorageClass:            aws.String("StorageClass"),
		WebsiteRedirectLocation: aws.String("WebsiteRedirectLocation"),
	}
	resp, err := svc.CopyObject(params)

	if awserr := aws.Error(err); awserr != nil {
		// A service error occurred.
		fmt.Println("Error:", awserr.Code, awserr.Message)
	} else if err != nil {
		// A non-service error occurred.
		panic(err)
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Beispiel #10
0
func ExampleSWF_ListClosedWorkflowExecutions() {
	svc := swf.New(nil)

	params := &swf.ListClosedWorkflowExecutionsInput{
		Domain: aws.String("DomainName"), // Required
		CloseStatusFilter: &swf.CloseStatusFilter{
			Status: aws.String("CloseStatus"), // Required
		},
		CloseTimeFilter: &swf.ExecutionTimeFilter{
			OldestDate: aws.Time(time.Now()), // Required
			LatestDate: aws.Time(time.Now()),
		},
		ExecutionFilter: &swf.WorkflowExecutionFilter{
			WorkflowID: aws.String("WorkflowId"), // Required
		},
		MaximumPageSize: aws.Long(1),
		NextPageToken:   aws.String("PageToken"),
		ReverseOrder:    aws.Boolean(true),
		StartTimeFilter: &swf.ExecutionTimeFilter{
			OldestDate: aws.Time(time.Now()), // Required
			LatestDate: aws.Time(time.Now()),
		},
		TagFilter: &swf.TagFilter{
			Tag: aws.String("Tag"), // Required
		},
		TypeFilter: &swf.WorkflowTypeFilter{
			Name:    aws.String("Name"), // Required
			Version: aws.String("VersionOptional"),
		},
	}
	resp, err := svc.ListClosedWorkflowExecutions(params)

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			// Generic AWS Error with Code, Message, and original error (if any)
			fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				// A service error occurred
				fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			// This case should never be hit, The SDK should alwsy return an
			// error which satisfies the awserr.Error interface.
			fmt.Println(err.Error())
		}
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Beispiel #11
0
func ExampleSSM_UpdateAssociationStatus() {
	svc := ssm.New(nil)

	params := &ssm.UpdateAssociationStatusInput{
		AssociationStatus: &ssm.AssociationStatus{ // Required
			Date:           aws.Time(time.Now()),                // Required
			Message:        aws.String("StatusMessage"),         // Required
			Name:           aws.String("AssociationStatusName"), // Required
			AdditionalInfo: aws.String("StatusAdditionalInfo"),
		},
		InstanceID: aws.String("InstanceId"),   // Required
		Name:       aws.String("DocumentName"), // Required
	}
	resp, err := svc.UpdateAssociationStatus(params)

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			// Generic AWS Error with Code, Message, and original error (if any)
			fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				// A service error occurred
				fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			// This case should never be hit, The SDK should alwsy return an
			// error which satisfies the awserr.Error interface.
			fmt.Println(err.Error())
		}
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Beispiel #12
0
func TestInputService7ProtocolTestTimestampValuesCase1(t *testing.T) {
	svc := NewInputService7ProtocolTest(nil)
	svc.Endpoint = "https://test"

	input := &InputService7TestShapeInputShape{
		TimeArg: aws.Time(time.Unix(1422172800, 0)),
	}
	req, _ := svc.InputService7TestCaseOperation1Request(input)
	r := req.HTTPRequest

	// build request
	query.Build(req)
	assert.NoError(t, req.Error)

	// assert body
	assert.NotNil(t, r.Body)
	body, _ := ioutil.ReadAll(r.Body)
	assert.Equal(t, util.Trim(`Action=OperationName&TimeArg=2015-01-25T08%3A00%3A00Z&Version=2014-01-01`), util.Trim(string(body)))

	// assert URL
	assert.Equal(t, "https://test/", r.URL.String())

	// assert headers

}
Beispiel #13
0
func TestInputService2ProtocolTestTimestampValuesCase1(t *testing.T) {
	svc := NewInputService2ProtocolTest(nil)
	svc.Endpoint = "https://test"

	input := &InputService2TestShapeInputShape{
		TimeArg: aws.Time(time.Unix(1422172800, 0)),
	}
	req, _ := svc.InputService2TestCaseOperation1Request(input)
	r := req.HTTPRequest

	// build request
	jsonrpc.Build(req)
	assert.NoError(t, req.Error)

	// assert body
	assert.NotNil(t, r.Body)
	body, _ := ioutil.ReadAll(r.Body)
	assert.Equal(t, util.Trim(`{"TimeArg":1422172800}`), util.Trim(string(body)))

	// assert URL
	assert.Equal(t, "https://test/", r.URL.String())

	// assert headers
	assert.Equal(t, "application/x-amz-json-1.1", r.Header.Get("Content-Type"))
	assert.Equal(t, "com.amazonaws.foo.OperationName", r.Header.Get("X-Amz-Target"))

}
Beispiel #14
0
func TestInputService9ProtocolTestTimestampValuesCase1(t *testing.T) {
	svc := NewInputService9ProtocolTest(nil)
	svc.Endpoint = "https://test"

	input := &InputService9TestShapeInputShape{
		TimeArg: aws.Time(time.Unix(1422172800, 0)),
	}
	req, _ := svc.InputService9TestCaseOperation1Request(input)
	r := req.HTTPRequest

	// build request
	restjson.Build(req)
	assert.NoError(t, req.Error)

	// assert body
	assert.NotNil(t, r.Body)
	body, _ := ioutil.ReadAll(r.Body)
	assert.Equal(t, util.Trim(`{"TimeArg":1422172800}`), util.Trim(string(body)))

	// assert URL
	assert.Equal(t, "https://test/path", r.URL.String())

	// assert headers

}
Beispiel #15
0
func (c *client) findExecution(id string) (*swf.WorkflowExecution, error) {
	open, err := c.c.ListOpenWorkflowExecutions(&swf.ListOpenWorkflowExecutionsInput{
		Domain:          S(c.f.Domain),
		MaximumPageSize: aws.Long(1),
		StartTimeFilter: &swf.ExecutionTimeFilter{OldestDate: aws.Time(time.Unix(0, 0))},
		ExecutionFilter: &swf.WorkflowExecutionFilter{
			WorkflowID: S(id),
		},
	})

	if err != nil {
		if ae, ok := err.(awserr.Error); ok {
			log.Printf("component=client fn=findExecution at=list-open error-type=%s message=%s", ae.Code(), ae.Message())
		} else {
			log.Printf("component=client fn=findExecution at=list-open error=%s", err)
		}
		return nil, err
	}

	if len(open.ExecutionInfos) == 1 {
		return open.ExecutionInfos[0].Execution, nil
	} else {
		closed, err := c.c.ListClosedWorkflowExecutions(&swf.ListClosedWorkflowExecutionsInput{
			Domain:          S(c.f.Domain),
			MaximumPageSize: aws.Long(1),
			StartTimeFilter: &swf.ExecutionTimeFilter{OldestDate: aws.Time(time.Unix(0, 0))},
			ExecutionFilter: &swf.WorkflowExecutionFilter{
				WorkflowID: S(id),
			},
		})

		if err != nil {
			if ae, ok := err.(awserr.Error); ok {
				log.Printf("component=client fn=findExecution at=list-closed error-type=%s message=%s", ae.Code(), ae.Message())
			} else {
				log.Printf("component=client fn=findExecution at=list-closed error=%s", err)
			}
			return nil, err
		}

		if len(closed.ExecutionInfos) > 0 {
			return closed.ExecutionInfos[0].Execution, nil
		} else {
			return nil, errors.Trace(fmt.Errorf("workflow not found for id %s", id))
		}
	}
}
Beispiel #16
0
func ExampleS3_PutBucketLifecycle() {
	svc := s3.New(nil)

	params := &s3.PutBucketLifecycleInput{
		Bucket:     aws.String("BucketName"), // Required
		ContentMD5: aws.String("ContentMD5"),
		LifecycleConfiguration: &s3.LifecycleConfiguration{
			Rules: []*s3.Rule{ // Required
				&s3.Rule{ // Required
					Prefix: aws.String("Prefix"),           // Required
					Status: aws.String("ExpirationStatus"), // Required
					Expiration: &s3.LifecycleExpiration{
						Date: aws.Time(time.Now()),
						Days: aws.Long(1),
					},
					ID: aws.String("ID"),
					NoncurrentVersionExpiration: &s3.NoncurrentVersionExpiration{
						NoncurrentDays: aws.Long(1),
					},
					NoncurrentVersionTransition: &s3.NoncurrentVersionTransition{
						NoncurrentDays: aws.Long(1),
						StorageClass:   aws.String("TransitionStorageClass"),
					},
					Transition: &s3.Transition{
						Date:         aws.Time(time.Now()),
						Days:         aws.Long(1),
						StorageClass: aws.String("TransitionStorageClass"),
					},
				},
				// More values...
			},
		},
	}
	resp, err := svc.PutBucketLifecycle(params)

	if awserr := aws.Error(err); awserr != nil {
		// A service error occurred.
		fmt.Println("Error:", awserr.Code, awserr.Message)
	} else if err != nil {
		// A non-service error occurred.
		panic(err)
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Beispiel #17
0
func ExampleCloudWatch_GetMetricStatistics() {
	svc := cloudwatch.New(nil)

	params := &cloudwatch.GetMetricStatisticsInput{
		EndTime:    aws.Time(time.Now()),     // Required
		MetricName: aws.String("MetricName"), // Required
		Namespace:  aws.String("Namespace"),  // Required
		Period:     aws.Long(1),              // Required
		StartTime:  aws.Time(time.Now()),     // Required
		Statistics: []*string{ // Required
			aws.String("Statistic"), // Required
			// More values...
		},
		Dimensions: []*cloudwatch.Dimension{
			&cloudwatch.Dimension{ // Required
				Name:  aws.String("DimensionName"),  // Required
				Value: aws.String("DimensionValue"), // Required
			},
			// More values...
		},
		Unit: aws.String("StandardUnit"),
	}
	resp, err := svc.GetMetricStatistics(params)

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			// Generic AWS Error with Code, Message, and original error (if any)
			fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				// A service error occurred
				fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			// This case should never be hit, The SDK should alwsy return an
			// error which satisfies the awserr.Error interface.
			fmt.Println(err.Error())
		}
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Beispiel #18
0
func ExampleCloudTrail_LookupEvents() {
	svc := cloudtrail.New(nil)

	params := &cloudtrail.LookupEventsInput{
		EndTime: aws.Time(time.Now()),
		LookupAttributes: []*cloudtrail.LookupAttribute{
			&cloudtrail.LookupAttribute{ // Required
				AttributeKey:   aws.String("LookupAttributeKey"), // Required
				AttributeValue: aws.String("String"),             // Required
			},
			// More values...
		},
		MaxResults: aws.Long(1),
		NextToken:  aws.String("NextToken"),
		StartTime:  aws.Time(time.Now()),
	}
	resp, err := svc.LookupEvents(params)

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			// Generic AWS Error with Code, Message, and original error (if any)
			fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				// A service error occurred
				fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			// This case should never be hit, The SDK should alwsy return an
			// error which satisfies the awserr.Error interface.
			fmt.Println(err.Error())
		}
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Beispiel #19
0
func ExampleCodeDeploy_ListDeployments() {
	svc := codedeploy.New(nil)

	params := &codedeploy.ListDeploymentsInput{
		ApplicationName: aws.String("ApplicationName"),
		CreateTimeRange: &codedeploy.TimeRange{
			End:   aws.Time(time.Now()),
			Start: aws.Time(time.Now()),
		},
		DeploymentGroupName: aws.String("DeploymentGroupName"),
		IncludeOnlyStatuses: []*string{
			aws.String("DeploymentStatus"), // Required
			// More values...
		},
		NextToken: aws.String("NextToken"),
	}
	resp, err := svc.ListDeployments(params)

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			// Generic AWS Error with Code, Message, and original error (if any)
			fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				// A service error occurred
				fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			// This case should never be hit, The SDK should alwsy return an
			// error which satisfies the awserr.Error interface.
			fmt.Println(err.Error())
		}
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Beispiel #20
0
func ExampleElasticBeanstalk_DescribeEvents() {
	svc := elasticbeanstalk.New(nil)

	params := &elasticbeanstalk.DescribeEventsInput{
		ApplicationName: aws.String("ApplicationName"),
		EndTime:         aws.Time(time.Now()),
		EnvironmentID:   aws.String("EnvironmentId"),
		EnvironmentName: aws.String("EnvironmentName"),
		MaxRecords:      aws.Long(1),
		NextToken:       aws.String("Token"),
		RequestID:       aws.String("RequestId"),
		Severity:        aws.String("EventSeverity"),
		StartTime:       aws.Time(time.Now()),
		TemplateName:    aws.String("ConfigurationTemplateName"),
		VersionLabel:    aws.String("VersionLabel"),
	}
	resp, err := svc.DescribeEvents(params)

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			// Generic AWS Error with Code, Message, and original error (if any)
			fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				// A service error occurred
				fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			// This case should never be hit, The SDK should alwsy return an
			// error which satisfies the awserr.Error interface.
			fmt.Println(err.Error())
		}
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Beispiel #21
0
func ExampleCloudWatch_PutMetricData() {
	svc := cloudwatch.New(nil)

	params := &cloudwatch.PutMetricDataInput{
		MetricData: []*cloudwatch.MetricDatum{ // Required
			&cloudwatch.MetricDatum{ // Required
				MetricName: aws.String("MetricName"), // Required
				Dimensions: []*cloudwatch.Dimension{
					&cloudwatch.Dimension{ // Required
						Name:  aws.String("DimensionName"),  // Required
						Value: aws.String("DimensionValue"), // Required
					},
					// More values...
				},
				StatisticValues: &cloudwatch.StatisticSet{
					Maximum:     aws.Double(1.0), // Required
					Minimum:     aws.Double(1.0), // Required
					SampleCount: aws.Double(1.0), // Required
					Sum:         aws.Double(1.0), // Required
				},
				Timestamp: aws.Time(time.Now()),
				Unit:      aws.String("StandardUnit"),
				Value:     aws.Double(1.0),
			},
			// More values...
		},
		Namespace: aws.String("Namespace"), // Required
	}
	resp, err := svc.PutMetricData(params)

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			// Generic AWS Error with Code, Message, and original error (if any)
			fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				// A service error occurred
				fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			// This case should never be hit, The SDK should alwsy return an
			// error which satisfies the awserr.Error interface.
			fmt.Println(err.Error())
		}
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Beispiel #22
0
func ExampleCognitoSync_UpdateRecords() {
	svc := cognitosync.New(nil)

	params := &cognitosync.UpdateRecordsInput{
		DatasetName:      aws.String("DatasetName"),      // Required
		IdentityID:       aws.String("IdentityId"),       // Required
		IdentityPoolID:   aws.String("IdentityPoolId"),   // Required
		SyncSessionToken: aws.String("SyncSessionToken"), // Required
		ClientContext:    aws.String("ClientContext"),
		DeviceID:         aws.String("DeviceId"),
		RecordPatches: []*cognitosync.RecordPatch{
			&cognitosync.RecordPatch{ // Required
				Key:                    aws.String("RecordKey"), // Required
				Op:                     aws.String("Operation"), // Required
				SyncCount:              aws.Long(1),             // Required
				DeviceLastModifiedDate: aws.Time(time.Now()),
				Value: aws.String("RecordValue"),
			},
			// More values...
		},
	}
	resp, err := svc.UpdateRecords(params)

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			// Generic AWS Error with Code, Message, and original error (if any)
			fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				// A service error occurred
				fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			// This case should never be hit, The SDK should alwsy return an
			// error which satisfies the awserr.Error interface.
			fmt.Println(err.Error())
		}
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Beispiel #23
0
func TestInputService9ProtocolTestTimestampValuesCase2(t *testing.T) {
	svc := NewInputService9ProtocolTest(nil)
	svc.Endpoint = "https://test"

	input := &InputService9TestShapeInputShape{
		TimeArgInHeader: aws.Time(time.Unix(1422172800, 0)),
	}
	req, _ := svc.InputService9TestCaseOperation2Request(input)
	r := req.HTTPRequest

	// build request
	restjson.Build(req)
	assert.NoError(t, req.Error)

	// assert URL
	assert.Equal(t, "https://test/path", r.URL.String())

	// assert headers
	assert.Equal(t, "Sun, 25 Jan 2015 08:00:00 GMT", r.Header.Get("x-amz-timearg"))

}
Beispiel #24
0
func (c *client) WalkOpenWorkflowInfos(template *swf.ListOpenWorkflowExecutionsInput, workflowInfosFunc WorkflowInfosFunc) error {
	template.Domain = S(c.f.Domain)

	if template.StartTimeFilter == nil {
		template.StartTimeFilter = &swf.ExecutionTimeFilter{OldestDate: aws.Time(time.Unix(0, 0))}
	}

	if template.TypeFilter == nil && template.ExecutionFilter == nil && template.TagFilter == nil {
		template.TypeFilter = &swf.WorkflowTypeFilter{Name: S(c.f.Name)}
	}

	infos, err := c.c.ListOpenWorkflowExecutions(template)

	for {
		if err != nil {
			return err
		}

		err := workflowInfosFunc(infos)

		if err != nil {
			if IsStopWalking(err) {
				return nil
			}
			return err
		}

		if infos.NextPageToken == nil {
			break
		}

		template.NextPageToken = infos.NextPageToken
		infos, err = c.c.ListOpenWorkflowExecutions(template)
	}

	return nil
}
Beispiel #25
0
func ExampleElasticBeanstalk_DescribeEnvironments() {
	svc := elasticbeanstalk.New(nil)

	params := &elasticbeanstalk.DescribeEnvironmentsInput{
		ApplicationName: aws.String("ApplicationName"),
		EnvironmentIDs: []*string{
			aws.String("EnvironmentId"), // Required
			// More values...
		},
		EnvironmentNames: []*string{
			aws.String("EnvironmentName"), // Required
			// More values...
		},
		IncludeDeleted:        aws.Boolean(true),
		IncludedDeletedBackTo: aws.Time(time.Now()),
		VersionLabel:          aws.String("VersionLabel"),
	}
	resp, err := svc.DescribeEnvironments(params)

	if err != nil {
		if awsErr, ok := err.(awserr.Error); ok {
			// Generic AWS Error with Code, Message, and original error (if any)
			fmt.Println(awsErr.Code(), awsErr.Message(), awsErr.OrigErr())
			if reqErr, ok := err.(awserr.RequestFailure); ok {
				// A service error occurred
				fmt.Println(reqErr.Code(), reqErr.Message(), reqErr.StatusCode(), reqErr.RequestID())
			}
		} else {
			// This case should never be hit, The SDK should alwsy return an
			// error which satisfies the awserr.Error interface.
			fmt.Println(err.Error())
		}
	}

	// Pretty-print the response data.
	fmt.Println(awsutil.StringValue(resp))
}
Beispiel #26
0
func TestListNoPattern(t *testing.T) {
	utc1 := time.FixedZone("X", -3600)

	fakeS3 := &FakeS3{
		ListOutputs: []s3.ListObjectsOutput{
			{
				Contents: []*s3.Object{
					{
						Key:          aws.String("secrets/one"),
						ETag:         aws.String(`"etag1"`),
						Size:         aws.Long(1004 + 224),
						LastModified: aws.Time(time.Date(2006, 1, 2, 15, 4, 5, 0, utc1)),
					},
					{
						Key:          aws.String("secrets/two"),
						ETag:         aws.String(`"etag2"`),
						Size:         aws.Long(1005 + 224),
						LastModified: aws.Time(time.Date(2007, 1, 2, 15, 4, 5, 0, utc1)),
					},
					{
						Key:          aws.String("secrets/winkle"),
						ETag:         aws.String(`"etag3"`),
						Size:         aws.Long(1006 + 224),
						LastModified: aws.Time(time.Date(2008, 1, 2, 15, 4, 5, 0, utc1)),
					},
				},
			},
		},
	}

	man := Manager{
		Objects: fakeS3,
		Bucket:  "bucket",
		Prefix:  "secrets/",
	}

	actual, err := man.List("")
	if err != nil {
		t.Fatal(err)
	}

	expected := []File{
		File{
			Path:         "one",
			LastModified: time.Date(2006, 1, 2, 16, 4, 5, 0, time.UTC),
			Size:         1004,
			ETag:         "etag1",
		},
		File{
			Path:         "two",
			LastModified: time.Date(2007, 1, 2, 16, 4, 5, 0, time.UTC),
			Size:         1005,
			ETag:         "etag2",
		},
		File{
			Path:         "winkle",
			LastModified: time.Date(2008, 1, 2, 16, 4, 5, 0, time.UTC),
			Size:         1006,
			ETag:         "etag3",
		},
	}

	if !reflect.DeepEqual(actual, expected) {
		t.Errorf("Was %#v\n but expected \n%#v", actual, expected)
	}

	req := fakeS3.ListInputs[0]

	if v, want := *req.Bucket, "bucket"; v != want {
		t.Errorf("Bucket was %q but expected %q", v, want)
	}

	if v, want := *req.Prefix, "secrets/"; v != want {
		t.Errorf("Prefix was %q but expected %q", v, want)
	}
}
Beispiel #27
0
func (m *Monitor) monitorPolicy(p *Policy) {
	//first, get historical data dump
	m.RLock()
	pData := m.policies[p]
	m.RUnlock()
	m.credsLock.Lock()
	cli := ec2.New(m.creds, p.Region, nil)
	m.credsLock.Unlock()
	//Fetch historical data
	pData.Lock()
	log.Println("Fetching historical data!")
	var requestParameters ec2.DescribeSpotPriceHistoryRequest
	requestParameters.InstanceTypes = []string{p.InstanceType}
	requestParameters.ProductDescriptions = []string{p.ProductDescription}
	requestParameters.AvailabilityZone = aws.String(p.AvailabilityZone)
	resp, err := cli.DescribeSpotPriceHistory(&requestParameters)
	if err != nil {
		panic(err)
	}
	for _, spotPrice := range resp.SpotPriceHistory {
		price, err := strconv.ParseFloat(*spotPrice.SpotPrice, 64)
		if err != nil {
			panic(err)
		}
		pData.priceData = append(pData.priceData, &PriceDatum{*spotPrice.AvailabilityZone, *spotPrice.InstanceType, *spotPrice.ProductDescription, price, spotPrice.Timestamp})
	}
	sort.Sort(byTimestamp(pData.priceData))
	pData.Unlock()
	//Now check for new data
	for {
		select {
		case <-p.done:
			close(p.channel)
			p.channel = nil
			break
		case <-time.After(time.Second * 30):
			pData.Lock()
			requestParameters.StartTime = aws.Time(pData.priceData[len(pData.priceData)-1].Timestamp.Add(time.Millisecond * 5))
			resp, err := cli.DescribeSpotPriceHistory(&requestParameters)
			if err != nil {
				panic(err)
			}
			//TODO: should sort incoming price data chronologically, even if the API says it will be sorted.
			for i, spotPrice := range resp.SpotPriceHistory {
				price, err := strconv.ParseFloat(*spotPrice.SpotPrice, 64)
				if err != nil {
					panic(err)
				}
				datum := &PriceDatum{*spotPrice.AvailabilityZone, *spotPrice.InstanceType, *spotPrice.ProductDescription, price, spotPrice.Timestamp}
				//Filter out duplicates, AWS seems to send the current price regardless of the StartTime
				if *pData.priceData[len(pData.priceData)-len(resp.SpotPriceHistory)+i] == *datum {
					continue
				}
				p.channel <- datum
				pData.priceData = append(pData.priceData)
			}
			pData.Unlock()
		}
		if p.channel == nil {
			break
		}
	}
}
Beispiel #28
0
func TestRotate(t *testing.T) {
	oldKey := func() []byte {
		return make([]byte, 32)
	}

	newKey := func() []byte {
		k := oldKey()
		k[0] = 100
		return k
	}

	oldCiphertext := []byte{
		0x00, 0x00, 0x00, 0x0d, 0x65, 0x6e, 0x63, 0x72, 0x79, 0x70, 0x74, 0x65,
		0x64, 0x20, 0x6b, 0x65, 0x79, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0xba, 0xcf, 0x29, 0x4e, 0x6d, 0x09, 0x18,
		0x4e, 0x66, 0x6e, 0xb1, 0xb6, 0xc9, 0x87, 0x65, 0xcc, 0xe1, 0x06, 0x8c,
		0xbf, 0x7f, 0xdd, 0x5d, 0x70, 0x4e, 0x3d, 0xbf, 0xd5, 0x44, 0xec,
	}

	fakeS3 := &FakeS3{
		ListOutputs: []s3.ListObjectsOutput{
			{
				Contents: []*s3.Object{
					{
						Key:          aws.String("secrets/weeble.txt"),
						ETag:         aws.String(`"etag1"`),
						Size:         aws.Long(1004),
						LastModified: aws.Time(time.Date(2006, 1, 2, 15, 4, 5, 0, time.UTC)),
					},
				},
			},
		},
		GetOutputs: []s3.GetObjectOutput{
			{
				Body: ioutil.NopCloser(bytes.NewReader(oldCiphertext)),
			},
		},
		PutOutputs: []s3.PutObjectOutput{
			{},
			{},
		},
	}
	fakeKMS := &FakeKMS{
		DecryptOutputs: []kms.DecryptOutput{
			{
				KeyID:     aws.String("key1"),
				Plaintext: oldKey(),
			},
		},
		GenerateOutputs: []kms.GenerateDataKeyOutput{
			{
				CiphertextBlob: []byte("encrypted new key"),
				KeyID:          aws.String("key1"),
				Plaintext:      newKey(),
			},
		},
	}

	man := Manager{
		Objects: fakeS3,
		Envelope: Envelope{
			KMS: fakeKMS,
		},
		KeyID:  "key1",
		Bucket: "bucket",
		Prefix: "secrets",
	}

	if err := man.Rotate("", nil); err != nil {
		t.Fatal(err)
	}

	// KMS request

	genReq := fakeKMS.GenerateInputs[0]
	if v, want := *genReq.KeyID, "key1"; v != want {
		t.Errorf("Key ID was %q, but expected %q", v, want)
	}

	if v, want := *genReq.KeySpec, "AES_256"; v != want {
		t.Errorf("Key spec was %v, but expected %v", v, want)
	}

	putReq := fakeS3.PutInputs[0]
	if v, want := *putReq.Bucket, "bucket"; v != want {
		t.Errorf("Bucket was %q, but expected %q", v, want)
	}

	if v, want := *putReq.Key, "secrets/weeble.txt"; v != want {
		t.Errorf("Key was %q, but expected %q", v, want)
	}

	if v, want := *putReq.ContentLength, int64(63); v != want {
		t.Errorf("ContentLength was %d, but expected %d", v, want)
	}

	if v, want := *putReq.ContentType, "application/octet-stream"; v != want {
		t.Errorf("ContentType was %q, but expected %q", v, want)
	}

	actual, err := ioutil.ReadAll(putReq.Body)
	if err != nil {
		t.Fatal(err)
	}

	header := actual[:4]
	if v := []byte{0x00, 0x00, 0x00, 0x11}; !bytes.Equal(header, v) {
		t.Errorf("Header was %x but expected %x", header, v)
	}

	blob := actual[4 : 17+4]
	if v := []byte("encrypted new key"); !bytes.Equal(blob, v) {
		t.Errorf("Blob was %x but expected %x", blob, v)
	}

	ciphertext := actual[17+4:]
	plaintext, err := decrypt(newKey(), ciphertext, []byte("key1"))
	if err != nil {
		t.Fatal(err)
	}

	if v, want := string(plaintext), "this is a test"; v != want {
		t.Errorf("Plaintext was %x but expected %x", v, want)
	}
}