This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
terraform { | |
required_providers { | |
wavefront = { | |
source = "terraform-providers/wavefront" | |
version = "2.4.0" | |
} | |
} | |
required_version = ">= 0.13" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PetStoreFunction: | |
Type: AWS::Serverless::Function | |
Properties: | |
CodeUri: PetStoreFunction | |
Handler: com.petstore.App::handleRequest | |
Runtime: java11 | |
MemorySize: 512 | |
Environment: | |
Variables: | |
PARAM1: VALUE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return DynamoDbClient.builder() | |
.endpointOverride(URI.create("http://localhost:4566")) | |
.region(Region.US_WEST_1) | |
.httpClient(ApacheHttpClient.builder().build()) | |
.build(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: '3' | |
services: | |
localstack: | |
container_name: ${LOCALSTACK_DOCKER_NAME-localstack_main} | |
image: localstack/localstack | |
network_mode: bridge | |
ports: | |
- "4566:4566" | |
environment: | |
- SERVICES=dynamodb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try { | |
final String httpMethod = input.getHttpMethod(); | |
if ("GET".equalsIgnoreCase(httpMethod)) { | |
final List<Pet> pets = DependencyModule.PET_STORE_CLIENT.read(); | |
final String result = DependencyModule.OBJECT_MAPPER.writeValueAsString(pets); | |
return response.withStatusCode(200).withBody(result); | |
} else { | |
final Pet pet = DependencyModule.OBJECT_MAPPER.readValue(input.getBody(), Pet.class); | |
final String id = DependencyModule.PET_STORE_CLIENT.write(pet); | |
return response.withStatusCode(200).withBody(id); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public final class DependencyModule { | |
private static final DynamoDbClient DYNAMO_DB_CLIENT = dynamoDbClient(); | |
public static final PetStoreClient PET_STORE_CLIENT = new PetStoreClient(DYNAMO_DB_CLIENT); | |
public static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); | |
private static DynamoDbClient dynamoDbClient() { | |
return DynamoDbClient.builder() | |
.region(Region.US_WEST_1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import software.amazon.awssdk.services.dynamodb.model.ScanRequest; | |
import software.amazon.awssdk.services.dynamodb.model.ScanResponse; | |
.... | |
public List<Pet> read() { | |
final ScanRequest scanRequest = ScanRequest.builder() | |
.tableName("pet-store") | |
.build(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import software.amazon.awssdk.services.dynamodb.model.AttributeValue; | |
import software.amazon.awssdk.services.dynamodb.model.PutItemRequest; | |
.... | |
public String write(final Pet pet) { | |
final String id = UUID.randomUUID().toString(); | |
final PutItemRequest putItemRequest = PutItemRequest.builder() | |
.tableName("pet-store") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private final DynamoDbClient dynamoDbClient; | |
public PetStoreClient(final DynamoDbClient dynamoDbClient) { | |
this.dynamoDbClient = dynamoDbClient; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>software.amazon.awssdk</groupId> | |
<artifactId>dynamodb</artifactId> | |
<version>2.15.12</version> | |
</dependency> | |
<dependency> | |
<groupId>software.amazon.awssdk</groupId> | |
<artifactId>apache-client</artifactId> | |
<version>2.5.12</version> | |
</dependency> |