Skip to content

Instantly share code, notes, and snippets.

@girishramnani
Created October 13, 2019 12:06
Show Gist options
  • Save girishramnani/312591657687c099ec1da6af1516d6f0 to your computer and use it in GitHub Desktop.
Save girishramnani/312591657687c099ec1da6af1516d6f0 to your computer and use it in GitHub Desktop.
package main
type UserAction struct {
UserID string `dynamo:"ID,hash"`
Time time.Time `dynamo:",range"`
Seq int64 `dynamo:"Seq,range"`
UUID string
embeddedWithKeys
}
type embeddedWithKeys struct {
Embedded **[]byte `dynamo:"Embedded,hash"`
}
func main() {
create := &dynamodb.CreateTableInput{
AttributeDefinitions: []*dynamodb.AttributeDefinition{
{
AttributeName: aws.String("ID"),
AttributeType: aws.String("S"),
},
{
AttributeName: aws.String("Time"),
AttributeType: aws.String("S"),
},
{
AttributeName: aws.String("Seq"),
AttributeType: aws.String("N"),
},
{
AttributeName: aws.String("Embedded"),
AttributeType: aws.String("B"),
},
},
GlobalSecondaryIndexes: []*dynamodb.GlobalSecondaryIndex{{
IndexName: aws.String("Embedded-index"),
KeySchema: []*dynamodb.KeySchemaElement{{
AttributeName: aws.String("Embedded"),
KeyType: aws.String("HASH"),
}},
Projection: &dynamodb.Projection{
ProjectionType: aws.String("ALL"),
},
ProvisionedThroughput: &dynamodb.ProvisionedThroughput{
ReadCapacityUnits: aws.Int64(1),
WriteCapacityUnits: aws.Int64(2),
},
}},
KeySchema: []*dynamodb.KeySchemaElement{{
AttributeName: aws.String("ID"),
KeyType: aws.String("HASH"),
}, {
AttributeName: aws.String("Time"),
KeyType: aws.String("RANGE"),
}},
LocalSecondaryIndexes: []*dynamodb.LocalSecondaryIndex{{
IndexName: aws.String("ID-Seq-index"),
KeySchema: []*dynamodb.KeySchemaElement{{
AttributeName: aws.String("ID"),
KeyType: aws.String("HASH"),
}, {
AttributeName: aws.String("Seq"),
KeyType: aws.String("RANGE"),
}},
Projection: &dynamodb.Projection{
ProjectionType: aws.String("INCLUDE"),
NonKeyAttributes: []*string{aws.String("UUID")},
},
}},
ProvisionedThroughput: &dynamodb.ProvisionedThroughput{
ReadCapacityUnits: aws.Int64(4),
WriteCapacityUnits: aws.Int64(2),
},
Tags: []*dynamodb.Tag{
&dynamodb.Tag{
Key: aws.String("Tag-Key"),
Value: aws.String("Tag-Value"),
},
},
TableName: aws.String("UserActions"),
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment