本文整理汇总了Golang中github.com/aws/aws-sdk-go/aws.Time函数的典型用法代码示例。如果您正苦于以下问题:Golang Time函数的具体用法?Golang Time怎么用?Golang Time使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Time函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: get_metric_stats
func get_metric_stats(sess *session.Session, identity_name, target_id, metric_name, metric_namespace string) []*cloudwatch.Datapoint {
svc := cloudwatch.New(sess)
t := time.Now()
input := &cloudwatch.GetMetricStatisticsInput{
Namespace: aws.String(metric_namespace),
Statistics: []*string{aws.String("Average")},
EndTime: aws.Time(t),
Period: aws.Int64(300),
StartTime: aws.Time(t.Add(time.Duration(-10) * time.Minute)),
MetricName: aws.String(metric_name),
Dimensions: []*cloudwatch.Dimension{
{
Name: aws.String(identity_name),
Value: aws.String(target_id),
},
},
}
value, err := svc.GetMetricStatistics(input)
if err != nil {
fmt.Printf("[ERROR] Fail GetMetricStatistics API call: %s \n", err.Error())
return nil
}
return value.Datapoints
}
示例2: ExampleConfigService_GetResourceConfigHistory
func ExampleConfigService_GetResourceConfigHistory() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := configservice.New(sess)
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.Int64(1),
NextToken: aws.String("NextToken"),
}
resp, err := svc.GetResourceConfigHistory(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例3: awsGetELBHostCounts
func awsGetELBHostCounts(cw cloudwatch.CloudWatch, md *opentsdb.MultiDataPoint, loadBalancer *elb.LoadBalancerDescription) error {
search := cloudwatch.GetMetricStatisticsInput{
StartTime: aws.Time(time.Now().UTC().Add(time.Second * -60)),
EndTime: aws.Time(time.Now().UTC()),
MetricName: aws.String("HealthyHostCount"),
Period: &aws_period,
Statistics: []*string{aws.String("Average")},
Namespace: aws.String("AWS/ELB"),
Unit: aws.String("Count"),
Dimensions: []*cloudwatch.Dimension{{Name: aws.String("LoadBalancerName"), Value: loadBalancer.LoadBalancerName}},
}
resp, err := cw.GetMetricStatistics(&search)
if err != nil {
return err
}
for _, datapoint := range resp.Datapoints {
AddTS(md, awsELBHostsHealthy, datapoint.Timestamp.Unix(), *datapoint.Average, opentsdb.TagSet{"loadbalancer": *loadBalancer.LoadBalancerName}, metadata.Gauge, metadata.Count, descAWSELBHostCount)
}
search.MetricName = aws.String("UnhealthyHostCount")
resp, err = cw.GetMetricStatistics(&search)
if err != nil {
return err
}
if resp.Datapoints == nil {
AddTS(md, awsELBHostsUnHealthy, time.Now().UTC().Unix(), 0, opentsdb.TagSet{"loadbalancer": *loadBalancer.LoadBalancerName}, metadata.Gauge, metadata.Count, descAWSELBHostCount)
} else {
for _, datapoint := range resp.Datapoints {
AddTS(md, awsELBHostsUnHealthy, datapoint.Timestamp.Unix(), *datapoint.Average, opentsdb.TagSet{"loadbalancer": *loadBalancer.LoadBalancerName}, metadata.Gauge, metadata.Count, descAWSELBHostCount)
}
}
return nil
}
示例4: ExampleCloudWatch_DescribeAlarmHistory
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 always return an
// error which satisfies the awserr.Error interface.
fmt.Println(err.Error())
}
}
// Pretty-print the response data.
fmt.Println(awsutil.StringValue(resp))
}
示例5: ExampleAutoScaling_DescribeScheduledActions
func ExampleAutoScaling_DescribeScheduledActions() {
svc := autoscaling.New(session.New())
params := &autoscaling.DescribeScheduledActionsInput{
AutoScalingGroupName: aws.String("ResourceName"),
EndTime: aws.Time(time.Now()),
MaxRecords: aws.Int64(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 {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例6: ExampleRedshift_DescribeClusterSnapshots
func ExampleRedshift_DescribeClusterSnapshots() {
svc := redshift.New(session.New())
params := &redshift.DescribeClusterSnapshotsInput{
ClusterIdentifier: aws.String("String"),
EndTime: aws.Time(time.Now()),
Marker: aws.String("String"),
MaxRecords: aws.Int64(1),
OwnerAccount: aws.String("String"),
SnapshotIdentifier: aws.String("String"),
SnapshotType: aws.String("String"),
StartTime: aws.Time(time.Now()),
TagKeys: []*string{
aws.String("String"), // Required
// More values...
},
TagValues: []*string{
aws.String("String"), // Required
// More values...
},
}
resp, err := svc.DescribeClusterSnapshots(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例7: ExampleElastiCache_DescribeEvents
func ExampleElastiCache_DescribeEvents() {
svc := elasticache.New(nil)
params := &elasticache.DescribeEventsInput{
Duration: aws.Int64(1),
EndTime: aws.Time(time.Now()),
Marker: aws.String("String"),
MaxRecords: aws.Int64(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 always return an
// error which satisfies the awserr.Error interface.
fmt.Println(err.Error())
}
}
// Pretty-print the response data.
fmt.Println(awsutil.Prettify(resp))
}
示例8: ExampleAutoScaling_PutScheduledUpdateGroupAction
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 always return an
// error which satisfies the awserr.Error interface.
fmt.Println(err.Error())
}
}
// Pretty-print the response data.
fmt.Println(awsutil.StringValue(resp))
}
示例9: ExampleAutoScaling_DescribeScheduledActions
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 always return an
// error which satisfies the awserr.Error interface.
fmt.Println(err.Error())
}
}
// Pretty-print the response data.
fmt.Println(awsutil.StringValue(resp))
}
示例10: TestGetAuthorizationTokenCacheHitExpiredToken
func (suite *GetAuthorizationTokenTestSuite) TestGetAuthorizationTokenCacheHitExpiredToken() {
expiredAuthData := &ecrapi.AuthorizationData{
ProxyEndpoint: aws.String(testProxyEndpoint),
AuthorizationToken: aws.String(testToken),
ExpiresAt: aws.Time(time.Now().Add(-5 * time.Minute)),
}
testAuthData := &ecrapi.AuthorizationData{
ProxyEndpoint: aws.String(testProxyEndpoint),
AuthorizationToken: aws.String(testToken),
ExpiresAt: aws.Time(time.Now().Add(12 * time.Hour)),
}
suite.mockClient.EXPECT().GetAuthorizationToken(
&ecrapi.GetAuthorizationTokenInput{
RegistryIds: []*string{aws.String(testRegistryId)},
}).Return(&ecrapi.GetAuthorizationTokenOutput{
AuthorizationData: []*ecrapi.AuthorizationData{testAuthData},
}, nil)
suite.mockCache.EXPECT().Get(testRegistryId).Return(expiredAuthData, true)
suite.mockCache.EXPECT().Set(testRegistryId, testAuthData)
authorizationData, err := suite.ecrClient.GetAuthorizationToken(testRegistryId)
assert.NoError(suite.T(), err)
assert.Equal(suite.T(), testAuthData, authorizationData)
}
示例11: ExampleEMR_DescribeJobFlows
func ExampleEMR_DescribeJobFlows() {
svc := emr.New(session.New())
params := &emr.DescribeJobFlowsInput{
CreatedAfter: aws.Time(time.Now()),
CreatedBefore: aws.Time(time.Now()),
JobFlowIds: []*string{
aws.String("XmlString"), // Required
// More values...
},
JobFlowStates: []*string{
aws.String("JobFlowExecutionState"), // Required
// More values...
},
}
resp, err := svc.DescribeJobFlows(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例12: ExampleCloudTrail_ListPublicKeys
func ExampleCloudTrail_ListPublicKeys() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := cloudtrail.New(sess)
params := &cloudtrail.ListPublicKeysInput{
EndTime: aws.Time(time.Now()),
NextToken: aws.String("String"),
StartTime: aws.Time(time.Now()),
}
resp, err := svc.ListPublicKeys(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例13: ExampleEMR_ListClusters
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 always return an
// error which satisfies the awserr.Error interface.
fmt.Println(err.Error())
}
}
// Pretty-print the response data.
fmt.Println(awsutil.Prettify(resp))
}
示例14: ExampleWAF_GetSampledRequests
func ExampleWAF_GetSampledRequests() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := waf.New(sess)
params := &waf.GetSampledRequestsInput{
MaxItems: aws.Int64(1), // Required
RuleId: aws.String("ResourceId"), // Required
TimeWindow: &waf.TimeWindow{ // Required
EndTime: aws.Time(time.Now()), // Required
StartTime: aws.Time(time.Now()), // Required
},
WebAclId: aws.String("ResourceId"), // Required
}
resp, err := svc.GetSampledRequests(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
fmt.Println(err.Error())
return
}
// Pretty-print the response data.
fmt.Println(resp)
}
示例15: ExampleConfigService_GetResourceConfigHistory
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.Int64(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 always return an
// error which satisfies the awserr.Error interface.
fmt.Println(err.Error())
}
}
// Pretty-print the response data.
fmt.Println(awsutil.Prettify(resp))
}