Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions apigw-dynamodb-terraform/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ Once the application is deployed, you can test it using the following instructio
```
* Repeate the process as many times as you can, try doing it with different Pet Types
1. Invoke the DynamoDB **Query** action to query items by PetType in the DynamoDB table:
* Run the below command after you replace <KEY> and <URL> with the terraform output from earlier.
* Run the below command after you replace <KEY> and <URL> with the terraform output from earlier. Append the PetType to the URL (e.g. `/dog`).
```
curl -H 'x-api-key: <KEY>' --request GET '<URL>'
curl -H 'x-api-key: <KEY>' --request GET '<URL>/dog'
```
* Repeate the process as many times as you can with different Pet Types
* You should receive a "200 OK" response with a list of the matching results. Example:
```
{
"music": [
"pets": [
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: The README file was incorrect, preventing the tests from running properly. I've fixed it👍

{
"id": "45b33352-fea0-4e8b-8c7a-6be11ec4ff80",
"PetType": "dog",
Expand Down
15 changes: 9 additions & 6 deletions apigw-dynamodb-terraform/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 3.27"
version = "~> 6.0"
}
}

Expand Down Expand Up @@ -81,8 +81,11 @@ resource "aws_dynamodb_table" "MyDynamoDBTable" {
}

global_secondary_index {
name = "PetType-index"
hash_key = "PetType"
name = "PetType-index"
key_schema {
attribute_name = "PetType"
key_type = "HASH"
}
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hash_key - (Optional, Deprecated) Name of the hash key in the index; must be defined as an attribute in the resource. Mutually exclusive with key_schema. Use key_schema instead.
https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/dynamodb_table

write_capacity = 5
read_capacity = 5
projection_type = "INCLUDE"
Expand Down Expand Up @@ -119,7 +122,7 @@ resource "aws_api_gateway_rest_api" "MyApiGatewayRestApi" {
"type" : "aws",
"credentials" : "${aws_iam_role.APIGWRole.arn}",
"httpMethod" : "POST",
"uri" : "arn:aws:apigateway:${data.aws_region.current.name}:dynamodb:action/PutItem",
"uri" : "arn:aws:apigateway:${data.aws_region.current.id}:dynamodb:action/PutItem",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: It deprecated from Provider v6

"responses" : {
"default" : {
"statusCode" : "200",
Expand Down Expand Up @@ -157,7 +160,7 @@ resource "aws_api_gateway_rest_api" "MyApiGatewayRestApi" {
"type" : "aws",
"credentials" : "${aws_iam_role.APIGWRole.arn}",
"httpMethod" : "POST",
"uri" : "arn:aws:apigateway:${data.aws_region.current.name}:dynamodb:action/Query",
"uri" : "arn:aws:apigateway:${data.aws_region.current.id}:dynamodb:action/Query",
"responses" : {
"default" : {
"statusCode" : "200",
Expand Down Expand Up @@ -349,4 +352,4 @@ output "APIGW-URL" {
output "APIGW-Key" {
value = aws_api_gateway_usage_plan_key.MyAPIGWUsagePlanKey.value
description = "The APIGW Key to use for testing"
}
}