当前位置: 首页>>代码示例>>Golang>>正文


Golang DynamoDB.DescribeTable方法代码示例

本文整理汇总了Golang中github.com/aws/aws-sdk-go/service/dynamodb.DynamoDB.DescribeTable方法的典型用法代码示例。如果您正苦于以下问题:Golang DynamoDB.DescribeTable方法的具体用法?Golang DynamoDB.DescribeTable怎么用?Golang DynamoDB.DescribeTable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/aws/aws-sdk-go/service/dynamodb.DynamoDB的用法示例。


在下文中一共展示了DynamoDB.DescribeTable方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: ensureTableExists

// ensureTableExists creates a DynamoDB table with a given
// DynamoDB client. If the table already exists, it is not
// being reconfigured.
func ensureTableExists(client *dynamodb.DynamoDB, table string, readCapacity, writeCapacity int) error {
	_, err := client.DescribeTable(&dynamodb.DescribeTableInput{
		TableName: aws.String(table),
	})
	if awserr, ok := err.(awserr.Error); ok {
		if awserr.Code() == "ResourceNotFoundException" {
			_, err = client.CreateTable(&dynamodb.CreateTableInput{
				TableName: aws.String(table),
				ProvisionedThroughput: &dynamodb.ProvisionedThroughput{
					ReadCapacityUnits:  aws.Int64(int64(readCapacity)),
					WriteCapacityUnits: aws.Int64(int64(writeCapacity)),
				},
				KeySchema: []*dynamodb.KeySchemaElement{{
					AttributeName: aws.String("Path"),
					KeyType:       aws.String("HASH"),
				}, {
					AttributeName: aws.String("Key"),
					KeyType:       aws.String("RANGE"),
				}},
				AttributeDefinitions: []*dynamodb.AttributeDefinition{{
					AttributeName: aws.String("Path"),
					AttributeType: aws.String("S"),
				}, {
					AttributeName: aws.String("Key"),
					AttributeType: aws.String("S"),
				}},
			})
			if err != nil {
				return err
			}

			err = client.WaitUntilTableExists(&dynamodb.DescribeTableInput{
				TableName: aws.String(table),
			})
			if err != nil {
				return err
			}
		}
	}
	if err != nil {
		return err
	}
	return nil
}
开发者ID:geckoboard,项目名称:vault,代码行数:47,代码来源:dynamodb.go

示例2: tryCreateTable

// make sure session table exists
func tryCreateTable(db *dynamodb.DynamoDB, sessionTableName string, readCapacityUnits, writeCapacityUnits int64) error {

	describeTableInput := &dynamodb.DescribeTableInput{TableName: aws.String(sessionTableName)}
	if _, err := db.DescribeTable(describeTableInput); err != nil {
		awserr := err.(awserr.Error)
		if awserr.Code() == "ResourceNotFoundException" {
			// table does not exist - create now

			params := &dynamodb.CreateTableInput{
				TableName: aws.String(sessionTableName),
				AttributeDefinitions: []*dynamodb.AttributeDefinition{ // Required
					{ // Required
						AttributeName: aws.String("id"),
						AttributeType: aws.String("S"), // Required
					},
				},
				KeySchema: []*dynamodb.KeySchemaElement{ // Required
					{ // Required
						AttributeName: aws.String("id"),
						KeyType:       aws.String("HASH"), // Required
					},
				},
				ProvisionedThroughput: &dynamodb.ProvisionedThroughput{
					ReadCapacityUnits:  aws.Int64(readCapacityUnits),
					WriteCapacityUnits: aws.Int64(writeCapacityUnits),
				},
			}

			if _, err := db.CreateTable(params); err != nil {
				return err
			}

		} else {
			return err
		}
	}

	return nil

}
开发者ID:colinn,项目名称:dynamodbstore,代码行数:41,代码来源:dynamodbstore.go


注:本文中的github.com/aws/aws-sdk-go/service/dynamodb.DynamoDB.DescribeTable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。