本文整理匯總了Golang中github.com/aws/aws-sdk-go/service/kinesis.New函數的典型用法代碼示例。如果您正苦於以下問題:Golang New函數的具體用法?Golang New怎麽用?Golang New使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了New函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ExampleKinesis_DecreaseStreamRetentionPeriod
func ExampleKinesis_DecreaseStreamRetentionPeriod() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := kinesis.New(sess)
params := &kinesis.DecreaseStreamRetentionPeriodInput{
RetentionPeriodHours: aws.Int64(1), // Required
StreamName: aws.String("StreamName"), // Required
}
resp, err := svc.DecreaseStreamRetentionPeriod(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)
}
示例2: KinesisLoop
func KinesisLoop(event <-chan *d2k.Event, callback func(*d2k.Event) interface{}) {
// main driver for pushing events to Kinesis
svc := kinesis.New(&aws.Config{Region: "us-west-2"})
// Wait... for stream to be ready
for {
params := &kinesis.DescribeStreamInput{
StreamName: &KinesisStreamName,
}
if resp, err := svc.DescribeStream(params); err != nil {
if awsErr, ok := err.(awserr.Error); ok {
log.Fatalln("KinesisLoop:", awsErr.Code(), awsErr.Message())
} else {
log.Fatalln("KinesisLoop:", err)
}
} else if *resp.StreamDescription.StreamStatus == "ACTIVE" {
break
} else {
log.Println("KinesisLoop:", KinesisStreamName, "not active")
time.Sleep(1 * time.Second)
}
}
for one_event := range event {
msg := callback(one_event)
if data, err := json.Marshal(msg); err != nil {
log.Fatalln(err)
} else {
log.Println("KinesisLoop:", string(data))
// TODO: send Kinesis event
}
}
}
示例3: Consume
//Consume gets data from a shard of an AWS Kinesis stream and puts them in a Go channel, once every second.
func Consume(shardID string, streamName string, region string, shardIteratorType string, eventChannel chan []byte) {
svc := kinesis.New(session.New(), &aws.Config{Region: aws.String(region)})
getShardIteratorParams := &kinesis.GetShardIteratorInput{
ShardId: aws.String(shardID), // Required
ShardIteratorType: aws.String(shardIteratorType), // Required
StreamName: aws.String(streamName), // Required
}
shardIterator, err := svc.GetShardIterator(getShardIteratorParams)
if err != nil {
log.Panic(err)
}
nextShardIterator := shardIterator.ShardIterator
for {
getRecordsParams := &kinesis.GetRecordsInput{
ShardIterator: nextShardIterator, // Required
Limit: aws.Int64(1000),
}
getRecordsResp, err := svc.GetRecords(getRecordsParams)
if err != nil {
log.Panic(err)
}
for _, record := range getRecordsResp.Records {
eventChannel <- record.Data
}
nextShardIterator = getRecordsResp.NextShardIterator
time.Sleep(time.Second)
}
}
示例4: ExampleKinesis_SplitShard
func ExampleKinesis_SplitShard() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := kinesis.New(sess)
params := &kinesis.SplitShardInput{
NewStartingHashKey: aws.String("HashKey"), // Required
ShardToSplit: aws.String("ShardId"), // Required
StreamName: aws.String("StreamName"), // Required
}
resp, err := svc.SplitShard(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)
}
示例5: ExampleKinesis_UpdateShardCount
func ExampleKinesis_UpdateShardCount() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := kinesis.New(sess)
params := &kinesis.UpdateShardCountInput{
ScalingType: aws.String("ScalingType"), // Required
StreamName: aws.String("StreamName"), // Required
TargetShardCount: aws.Int64(1), // Required
}
resp, err := svc.UpdateShardCount(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: ExampleKinesis_PutRecord
func ExampleKinesis_PutRecord() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := kinesis.New(sess)
params := &kinesis.PutRecordInput{
Data: []byte("PAYLOAD"), // Required
PartitionKey: aws.String("PartitionKey"), // Required
StreamName: aws.String("StreamName"), // Required
ExplicitHashKey: aws.String("HashKey"),
SequenceNumberForOrdering: aws.String("SequenceNumber"),
}
resp, err := svc.PutRecord(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: NewKinesisBufferFlusher
// NewKinesisBufferFlusher returns a KinesisBufferFlusher configured with
// the stream name and partition key.
func NewKinesisBufferFlusher(name, partitionKey string) *KinesisBufferFlusher {
sess := session.New()
// Are we assuming a role?
roleARN := conf.GetString("role-arn")
if roleARN != "" {
sess.Config.Credentials = stscreds.NewCredentials(sess, roleARN, func(o *stscreds.AssumeRoleProvider) {
rsn := conf.GetString("role-session-name")
if rsn != "" {
o.RoleSessionName = rsn
}
})
}
region := conf.GetString("region")
if region != "" {
sess.Config.Region = aws.String(region)
}
return &KinesisBufferFlusher{
Name: aws.String(name),
PartitionKey: partitionKey,
kinesis: kinesis.New(sess),
}
}
示例8: ExampleKinesis_GetShardIterator
func ExampleKinesis_GetShardIterator() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := kinesis.New(sess)
params := &kinesis.GetShardIteratorInput{
ShardId: aws.String("ShardId"), // Required
ShardIteratorType: aws.String("ShardIteratorType"), // Required
StreamName: aws.String("StreamName"), // Required
StartingSequenceNumber: aws.String("SequenceNumber"),
Timestamp: aws.Time(time.Now()),
}
resp, err := svc.GetShardIterator(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)
}
示例9: ExampleKinesis_ListTagsForStream
func ExampleKinesis_ListTagsForStream() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := kinesis.New(sess)
params := &kinesis.ListTagsForStreamInput{
StreamName: aws.String("StreamName"), // Required
ExclusiveStartTagKey: aws.String("TagKey"),
Limit: aws.Int64(1),
}
resp, err := svc.ListTagsForStream(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)
}
示例10: ExampleKinesis_EnableEnhancedMonitoring
func ExampleKinesis_EnableEnhancedMonitoring() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := kinesis.New(sess)
params := &kinesis.EnableEnhancedMonitoringInput{
ShardLevelMetrics: []*string{ // Required
aws.String("MetricsName"), // Required
// More values...
},
StreamName: aws.String("StreamName"), // Required
}
resp, err := svc.EnableEnhancedMonitoring(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)
}
示例11: ExampleKinesis_GetRecords
func ExampleKinesis_GetRecords() {
sess, err := session.NewSession()
if err != nil {
fmt.Println("failed to create session,", err)
return
}
svc := kinesis.New(sess)
params := &kinesis.GetRecordsInput{
ShardIterator: aws.String("ShardIterator"), // Required
Limit: aws.Int64(1),
}
resp, err := svc.GetRecords(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: initialize
// Set defaults for all fields, initialize channel and client if not provided
func (stream *StreamWorker) initialize() error {
if stream.IteratorType == "" {
stream.IteratorType = ShardIteratorTypeLatest
}
if stream.BatchSize == 0 {
stream.BatchSize = DefaultBatchSize
}
if stream.SleepTime == 0 {
stream.SleepTime = DefaultSleepTime
}
if stream.Output == nil {
stream.Output = make(chan Record)
}
if stream.State == nil {
stream.State = make(chan WorkerState)
}
if stream.Client == nil {
stream.Client = kinesis.New(stream.AwsConfig)
}
Logger.WithFields(log.Fields{
"StreamWorker": stream,
"AWS": stream.AwsConfig,
}).Debug("StreamWorker initialized")
return nil
}
示例13: Connect
func (k *KinesisOutput) Connect() error {
// We attempt first to create a session to Kinesis using an IAMS role, if that fails it will fall through to using
// environment variables, and then Shared Credentials.
if k.Debug {
log.Printf("kinesis: Establishing a connection to Kinesis in %+v", k.Region)
}
Config := &aws.Config{
Region: aws.String(k.Region),
}
svc := kinesis.New(session.New(Config))
KinesisParams := &kinesis.ListStreamsInput{
Limit: aws.Int64(100),
}
resp, err := svc.ListStreams(KinesisParams)
if err != nil {
log.Printf("kinesis: Error in ListSteams API call : %+v \n", err)
}
if checkstream(resp.StreamNames, k.StreamName) {
if k.Debug {
log.Printf("kinesis: Stream Exists")
}
k.svc = svc
return nil
} else {
log.Printf("kinesis : You have configured a StreamName %+v which does not exist. exiting.", k.StreamName)
os.Exit(1)
}
return err
}
示例14: putRecord
// Put a single record.
func (kr KinesisRelay) putRecord(msg string) {
kr.logger.Info.Println("Attempting to put record into stream")
svc := kinesis.New(&kr.awsConfig)
// TODO real partition key.
params := &kinesis.PutRecordInput{
StreamName: aws.String(kr.config.Kinesis.StreamName),
PartitionKey: aws.String("1"),
Data: []byte(msg),
}
resp, err := svc.PutRecord(params)
if err != nil {
// Print the error, cast err to awserr.Error to get the Code and
// Message from an error.
kr.logger.Error.Printf("Error w/ PutRecord: %#v", err.Error())
return
}
kr.logger.Trace.Printf("PutRecord response: %#v", resp)
kr.logger.Info.Println("Done putting record!")
}
示例15: TestMigrateStreams
func TestMigrateStreams(t *testing.T) {
if os.Getenv("AWS_ACCESS_KEY_ID") == "" || os.Getenv("AWS_SECRET_ACCESS_KEY") == "" {
Log.Printf("WARNING: NO AWS CREDS SPECIFIED, SKIPPING MIGRATIONS TEST")
return
}
config := &aws.Config{
Credentials: credentials.NewEnvCredentials(),
Region: aws.String("us-east-1"),
}
client := kinesis.New(session.New(config))
sm := StreamMigrator{
Streams: []kinesis.CreateStreamInput{
kinesis.CreateStreamInput{
StreamName: aws.String(testDomain),
ShardCount: aws.Int64(1),
},
},
Client: client,
Timeout: 30,
}
sm.Migrate()
sm.Migrate()
}