Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(aws-apigateway-dynamodb): add optional resourceName parameter #898

Merged
merged 5 commits into from Feb 15, 2023

Conversation

fargito
Copy link
Contributor

@fargito fargito commented Feb 13, 2023

Fixes #848

Description of changes:

  • Add a resourceName on the ApiGatewayToDynamoDB construct

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: githubautobuild-for-cdk-v2
  • Commit ID: e438583
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@fargito fargito force-pushed the feat/dynamodb-apigateway-resource-name branch from a2f8e5b to 416173b Compare February 13, 2023 13:12
@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: githubautobuild-for-cdk-v2
  • Commit ID: a2f8e5b
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: githubautobuild-for-cdk-v2
  • Commit ID: 416173b
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link
Contributor

@biffgaut biffgaut left a comment

Choose a reason for hiding this comment

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

At least one of the integration tests is failing -

@aws-solutions-constructs/aws-apigateway-dynamodb:  ├─ [~] AttributeDefinitions
@aws-solutions-constructs/aws-apigateway-dynamodb:  │   └─ @@ -1,6 +1,10 @@
@aws-solutions-constructs/aws-apigateway-dynamodb:  │      [ ] [
@aws-solutions-constructs/aws-apigateway-dynamodb:  │      [ ]   {
@aws-solutions-constructs/aws-apigateway-dynamodb:  │      [-]     "AttributeName": "id",
@aws-solutions-constructs/aws-apigateway-dynamodb:  │      [+]     "AttributeName": "PK",
@aws-solutions-constructs/aws-apigateway-dynamodb:  │      [ ]     "AttributeType": "S"
@aws-solutions-constructs/aws-apigateway-dynamodb:  │      [+]   },
@aws-solutions-constructs/aws-apigateway-dynamodb:  │      [+]   {
@aws-solutions-constructs/aws-apigateway-dynamodb:  │      [+]     "AttributeName": "SK",
@aws-solutions-constructs/aws-apigateway-dynamodb:  │      [+]     "AttributeType": "S"
@aws-solutions-constructs/aws-apigateway-dynamodb:  │      [ ]   }
@aws-solutions-constructs/aws-apigateway-dynamodb:  │      [ ] ]
@aws-solutions-constructs/aws-apigateway-dynamodb:  └─ [~] KeySchema (requires replacement)
@aws-solutions-constructs/aws-apigateway-dynamodb:      └─ @@ -1,6 +1,10 @@
@aws-solutions-constructs/aws-apigateway-dynamodb:         [ ] [
@aws-solutions-constructs/aws-apigateway-dynamodb:         [ ]   {
@aws-solutions-constructs/aws-apigateway-dynamodb:         [-]     "AttributeName": "id",
@aws-solutions-constructs/aws-apigateway-dynamodb:         [+]     "AttributeName": "PK",
@aws-solutions-constructs/aws-apigateway-dynamodb:         [ ]     "KeyType": "HASH"
@aws-solutions-constructs/aws-apigateway-dynamodb:         [+]   },
@aws-solutions-constructs/aws-apigateway-dynamodb:         [+]   {
@aws-solutions-constructs/aws-apigateway-dynamodb:         [+]     "AttributeName": "SK",
@aws-solutions-constructs/aws-apigateway-dynamodb:         [+]     "KeyType": "RANGE"
@aws-solutions-constructs/aws-apigateway-dynamodb:         [ ]   }
@aws-solutions-constructs/aws-apigateway-dynamodb:         [ ] ]
@aws-solutions-constructs/aws-apigateway-dynamodb: Outputs

From a quick perusal, it looks like the PR changes the output for integ.additional-request-templates.ts.

@fargito
Copy link
Contributor Author

fargito commented Feb 13, 2023

I added an integration test, I'll check

@fargito fargito force-pushed the feat/dynamodb-apigateway-resource-name branch 2 times, most recently from 1c847b4 to cf28cbd Compare February 13, 2023 15:56
@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: githubautobuild-for-cdk-v2
  • Commit ID: 1c847b4
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: githubautobuild-for-cdk-v2
  • Commit ID: cf28cbd
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@fargito fargito force-pushed the feat/dynamodb-apigateway-resource-name branch 2 times, most recently from 4f8ad15 to 4272c67 Compare February 13, 2023 16:12
@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: githubautobuild-for-cdk-v2
  • Commit ID: 4f8ad15
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: githubautobuild-for-cdk-v2
  • Commit ID: 4272c67
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: githubautobuild-for-cdk-v2
  • Commit ID: 687ceff
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@fargito
Copy link
Contributor Author

fargito commented Feb 13, 2023

Ok, I managed to get it working!

Copy link
Contributor

@biffgaut biffgaut left a comment

Choose a reason for hiding this comment

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

Thanks for the submission! One thing to clear up - the initial issue we set out to fix was that the resourceName was tightly coupled to the partitionKey name. In this iteration they are still tightly coupled in the code for the readRequestTemplate at line 269, but now the partitionKeyName is assumed to be the same as the resourceName. Since the client must provide a partitionKeyName in the TableProps, this sets up a situation where a client could provide different values - which I think would lead to the read request not working as the partitionKeyName at line 281 would be incorrect.

We expected the readRequestTemplate to look like this:

      const readRequestTemplate = props.readRequestTemplate ??
        `{ \
          "TableName": "${this.dynamoTable.tableName}", \
          "KeyConditionExpression": "${partitionKeyName} = :v1", \
          "ExpressionAttributeValues": { \
            ":v1": { \
              "S": "$input.params('${resourceName}')" \
            } \
          } \
        }`;

That decouples the partitionKeyName and resourceName.

Integration test looks good, but we need an unit test or two to confirm the correctness of the Construct output (unit tests are in apigateway-dynamodb.test.ts)

@fargito fargito force-pushed the feat/dynamodb-apigateway-resource-name branch from 687ceff to 7980c93 Compare February 14, 2023 09:34
@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: githubautobuild-for-cdk-v2
  • Commit ID: 7980c93
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@fargito fargito force-pushed the feat/dynamodb-apigateway-resource-name branch from 7980c93 to a794aa1 Compare February 14, 2023 10:01
@fargito
Copy link
Contributor Author

fargito commented Feb 14, 2023

@biffgaut you're absolutely right, I edited this, and also added a unit test

@fargito fargito force-pushed the feat/dynamodb-apigateway-resource-name branch from a794aa1 to aa078d4 Compare February 14, 2023 10:03
@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: githubautobuild-for-cdk-v2
  • Commit ID: a794aa1
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: githubautobuild-for-cdk-v2
  • Commit ID: aa078d4
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@biffgaut
Copy link
Contributor

Looks like this is ready for review, but just want to confirm before diving in?

@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: githubautobuild-for-cdk-v2
  • Commit ID: 7f0b303
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@fargito
Copy link
Contributor Author

fargito commented Feb 14, 2023

That is correct @biffgaut 🙂

@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: githubautobuild-for-cdk-v2
  • Commit ID: a4a959b
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@biffgaut biffgaut merged commit 09e54ec into awslabs:main Feb 15, 2023
@biffgaut
Copy link
Contributor

Great contribution - Thanks!

@biffgaut
Copy link
Contributor

This will go out with the next release - since we just dropped a release yesterday the next one will probably in in the next week.

@fargito fargito deleted the feat/dynamodb-apigateway-resource-name branch February 16, 2023 11:20
@fargito
Copy link
Contributor Author

fargito commented Feb 16, 2023

Thanks a lot! 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ApiGatewayToDynamoDB: customize resource name on REST API
3 participants