Yes you can! Your params would be something like this, where operation is something like "", "=" const params = { TableName: tableName, IndexName: index, KeyConditionExpression: `${primaryKey} = :primarykey and ${sortKey} ${operation} :sortKey `, ExpressionAttributeValues: { ':primarykey': primaryKeyValue, ':sortkey': sortValue }, }; docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html#Query.KeyConditionExpressions
Hi Sam, I am new in serverless. I have a question, If we have set up the database like LSI, GSI in dynamoDB directly, Do we need to set up in yml file also?
No, you can query a database that you made in the console with serverless. You just need to use the correct table name and it will work the same. Setting it up in Serverless means you could copy everything to another account without having to do anything manually.
local secondary indexes are a very complex topic and there are specific limitations to them. The main one being that you can only create them when you create the table and can't add more in the future. There are also limitations around data size and that you can only query one primary key at once. To implement them in serverless would be very similar to creating a table with global secondary indexes. Just change the "GlobalSecondaryIndexes" in your serverless.yml resources to LocallSecondaryIndexes. The structure should be the same
Very good video, one question ... How could dynamodb queries be used to search by latitude and longitude distances? I would appreciate any information. thanks
Querying on multiple fields at the same time isn't something that is easy in Dynamo. What you can do is query on one field and then use a query filter on the other field to get the final results that you want.
Hi Sam, I hope you are doing well. I'm trying to make use of the property ScanForwardIndex which is set to false inorder to display the values in descending order. But I guess I'm not setting the property correctly because I keep on getting the error; Serverless Error --------------------------------------- An error occurred: MyDynamoDbTable - Encountered unsupported property ScanIndexForward. My serverless yml looks something like this; Resources: MyDynamoDbTable: Type: AWS::DynamoDB::Table Properties: TableName: ${self:custom.tableName} AttributeDefinitions: - AttributeName: ID AttributeType: S AttributeName AttributeType: S KeySchema: - AttributeName: ID KeyType: HASH BillingMode: PAY_PER_REQUEST GlobalSecondaryIndexes: - IndexName: KeySchema: - AttributeName: KeyType: HASH Projection: ProjectionType: ALL ScanIndexForward: false Any tips on how I can resolve this issue?
The ScanIndexForward value is used as part of a query request to the database, not on the configuration for the database. If you set it to false then the query response data will be ordered in reverse order. docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html#DDB-Query-request-ScanIndexForward
Thank you. How can i update a endpoint after deploy it. For example in place of {filename} i write {ID} and deploy it. when i try convert it into {filename} it is throwing Error.
@@CompleteCoding A sibling ({ID}) of this resource already has a variable path part -- only one is allowed (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException; Request ID: 146b2a96-0977-436c-9c9f-416357af77e7; Proxy: null).
Thanks Sam . Managed to use this to make queries of multiple indexes across multiple tables.
Great job!
now i'm tempted to watch all your videos. Great thanks:))
There are a lot of them now. I'd start by looking for the ones that you could use soon.
Great Video!!
Glad you enjoyed it
Thanks for the great video!
Can you share what KeyConditionExpression can be used to query a GSI and a sort key? Or is that an invalid operation?
Yes you can! Your params would be something like this, where operation is something like "", "="
const params = {
TableName: tableName,
IndexName: index,
KeyConditionExpression: `${primaryKey} = :primarykey and ${sortKey} ${operation} :sortKey `,
ExpressionAttributeValues: {
':primarykey': primaryKeyValue,
':sortkey': sortValue
},
};
docs.aws.amazon.com/amazondynamodb/latest/developerguide/Query.html#Query.KeyConditionExpressions
@@CompleteCoding thank you so much!
thanks alott man!!
Glad you like it
Good job
Thanks
Hi Sam, I am new in serverless. I have a question, If we have set up the database like LSI, GSI in dynamoDB directly, Do we need to set up in yml file also?
No, you can query a database that you made in the console with serverless. You just need to use the correct table name and it will work the same.
Setting it up in Serverless means you could copy everything to another account without having to do anything manually.
what is the difference in the implementation of global secondary indexes and a local secondary index in serverless?
local secondary indexes are a very complex topic and there are specific limitations to them. The main one being that you can only create them when you create the table and can't add more in the future. There are also limitations around data size and that you can only query one primary key at once.
To implement them in serverless would be very similar to creating a table with global secondary indexes. Just change the "GlobalSecondaryIndexes" in your serverless.yml resources to LocallSecondaryIndexes. The structure should be the same
Very good video, one question ...
How could dynamodb queries be used to search by latitude and longitude distances? I would appreciate any information. thanks
Querying on multiple fields at the same time isn't something that is easy in Dynamo.
What you can do is query on one field and then use a query filter on the other field to get the final results that you want.
Hi Sam, I hope you are doing well. I'm trying to make use of the property ScanForwardIndex which is set to false inorder to display the values in descending order. But I guess I'm not setting the property correctly because I keep on getting the error;
Serverless Error ---------------------------------------
An error occurred: MyDynamoDbTable - Encountered unsupported property ScanIndexForward.
My serverless yml looks something like this;
Resources:
MyDynamoDbTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: ${self:custom.tableName}
AttributeDefinitions:
- AttributeName: ID
AttributeType: S
AttributeName
AttributeType: S
KeySchema:
- AttributeName: ID
KeyType: HASH
BillingMode: PAY_PER_REQUEST
GlobalSecondaryIndexes:
- IndexName:
KeySchema:
- AttributeName:
KeyType: HASH
Projection:
ProjectionType: ALL
ScanIndexForward: false
Any tips on how I can resolve this issue?
The ScanIndexForward value is used as part of a query request to the database, not on the configuration for the database. If you set it to false then the query response data will be ordered in reverse order.
docs.aws.amazon.com/amazondynamodb/latest/APIReference/API_Query.html#DDB-Query-request-ScanIndexForward
Thank you. How can i update a endpoint after deploy it. For example in place of {filename} i write {ID} and deploy it. when i try convert it into {filename} it is throwing Error.
What is the error that it's throwing?
@@CompleteCoding A sibling ({ID}) of this resource already has a variable path part -- only one is allowed (Service: AmazonApiGateway; Status Code: 400; Error Code: BadRequestException; Request ID: 146b2a96-0977-436c-9c9f-416357af77e7; Proxy: null).
sir please upload a video on authorizers and authentication
I've had quite a few suggestions to do that so you should see a video on that coming out soon