Skip to content

Instantly share code, notes, and snippets.

@billydh
billydh / update-item-new-fields
Created January 13, 2020 11:12
Update item with new fields with return values
aws dynamodb update-item --endpoint-url http://localhost:8042 --table-name demo-customer-info \
--key '{"customerId": {"S": "1111"}}' \
--update-expression 'SET #lastName = :lastName, #dateOfBirth = :dateOfBirth' \
--expression-attribute-names '{"#lastName": "lastName", "#dateOfBirth": "dateOfBirth"}' \
--expression-attribute-values '{":lastName": {"S": "Jones"}, ":dateOfBirth": {"S": "1985-03-01"}}' \
--return-values ALL_NEW
aws dynamodb delete-item --endpoint-url http://localhost:8042 --table-name demo-customer-info \
--key '{"customerId": {"S": "1111"}}' \
--return-values ALL_OLD
docker-compose -f docker-compose-dynamodb.yaml down
aws dynamodb put-item --endpoint-url http://localhost:8042 --table-name demo-customer-info \
--item '{"customerId": {"S": "1111"}, "email": {"S": "[email protected]"}}' \
--condition-expression "attribute_not_exists(customerId)"
aws dynamodb update-item --endpoint-url http://localhost:8042 --table-name demo-customer-info \
--key '{"customerId": {"S": "1111"}}' \
--update-expression 'SET #isEligibleForPromotion = :eligibility' \
--expression-attribute-names '{"#isEligibleForPromotion": "isEligibleForPromotion", "#dateOfBirth": "dateOfBirth"}' \
--expression-attribute-values '{":eligibility": {"BOOL": true}, ":dateFrom": {"S": "1980-01-01"}}' \
--condition-expression "#dateOfBirth > :dateFrom" \
--return-values ALL_NEW
package io.codebrews.dynamodemo
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.stereotype.Component
@Component
@ConfigurationProperties(prefix = "application.dynamo")
data class DynamoConfigProperties(
var customerTableName: String = "",
var region: String = "",
@billydh
billydh / DynamoClientProperties.kt
Created January 15, 2020 11:47
DynamoClientProperties using DynamoConfigProperties
package io.codebrews.dynamodemo
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import software.amazon.awssdk.auth.credentials.DefaultCredentialsProvider
import software.amazon.awssdk.regions.Region
import software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient
import java.net.URI
@Configuration
@billydh
billydh / DynamoConfigProperties.kt
Created January 16, 2020 02:20
DynamoConfigProperties written using ConstructorBinding
package io.codebrews.dynamodemo
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.boot.context.properties.ConstructorBinding
@ConstructorBinding
@ConfigurationProperties(prefix = "application.dynamo")
data class DynamoConfigProperties(
val customerTableName: String,
val region: String,
@billydh
billydh / DynamodemoApplication.kt
Created January 16, 2020 02:37
DynamodemoApplication with ConfigurationPropertiesScan
package io.codebrews.dynamodemo
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.context.properties.ConfigurationPropertiesScan
import org.springframework.boot.runApplication
@SpringBootApplication
@ConfigurationPropertiesScan
class DynamodemoApplication
@billydh
billydh / DynamodemoApplication.kt
Created January 16, 2020 02:59
DynamodemoApplication with EnableConfigurationProperties
package io.codebrews.dynamodemo
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.boot.runApplication
@SpringBootApplication
@EnableConfigurationProperties(DynamoConfigProperties::class)
class DynamodemoApplication