ich den Serverless Framework Setup bin mit der folgenden Tabelle:DynamoDB: Abfrage auf GSI (Global Sekundärindex) nicht zurück Daten
provider:
name: aws
runtime: nodejs6.10
stage: dev
region: ap-southeast-1
environment:
DYNAMODB_TABLE: "Itinerary-${self:provider.stage}"
DYNAMODB_COUNTRY_INDEX: country_index
iamRoleStatements:
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource: "arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:provider.environment.DYNAMODB_TABLE}"
- Effect: Allow
Action:
- dynamodb:Query
- dynamodb:Scan
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
Resource: "arn:aws:dynamodb:${opt:region, self:provider.region}:*:table/${self:provider.environment.DYNAMODB_TABLE}/index/${self:provider.environment.DYNAMODB_COUNTRY_INDEX}"
resources:
Resources:
ItineraryTable:
Type: 'AWS::DynamoDB::Table'
DeletionPolicy: Retain
Properties:
AttributeDefinitions:
-
AttributeName: ID
AttributeType: S
-
AttributeName: Country
AttributeType: S
KeySchema:
-
AttributeName: ID
KeyType: HASH
GlobalSecondaryIndexes:
-
IndexName: ${self:provider.environment.DYNAMODB_COUNTRY_INDEX}
KeySchema:
-
AttributeName: Country
KeyType: HASH
Projection:
ProjectionType: ALL
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
ProvisionedThroughput:
ReadCapacityUnits: 1
WriteCapacityUnits: 1
TableName: ${self:provider.environment.DYNAMODB_TABLE}
Nun, ich bin in der Lage zu bekommen, eine zu tun, „get“ zu Elemente aus der DB nach ID abrufen. Wenn ich jedoch versuche, eine "Abfrage" an der GSI durchzuführen, gibt sie nichts zurück. Es gibt keinen Fehler, aber ich bekomme nie Daten zurück.
Die unten ist, was meine Frage wie folgt aussieht:
const dynamoDb = new AWS.DynamoDB.DocumentClient();
var params = {
TableName: process.env.DYNAMODB_TABLE, // maps back to the serverless config variable above
IndexName: process.env.DYNAMODB_COUNTRY_INDEX, // maps back to the serverless config variable above
KeyConditionExpression: "Country=:con",
ExpressionAttributeValues: { ":con" : "Portugal" }
};
dynamoDb.query(params, (error, result) => {
// handle potential errors
if (error) {
console.error(error);
callback(null, {
statusCode: error.statusCode || 501,
headers: { 'Content-Type': 'text/plain' },
body: 'Couldn\'t fetch the Itineraries'+error,
});
return;
}
}
var json_result = JSON.stringify(result.Item);
Ich sollte hinzufügen, dass ich keine Daten erhalten können, wenn ich einen filterless „Scan“ auch tun. Wenn ich auf dem AWS Dynamo-Webportal nach Objekten nach Index (oder auf andere Weise) suche, erhalte ich trotzdem Ergebnisse.
Ich kann nicht herausfinden, was hier falsch läuft. Jedes Licht, das jemand vergossen könnte, wäre sehr geschätzt.
Sind Sie sicher, dass Land mit demselben Fall (d. H. Kamelfall mit Großbuchstabe P) gespeichert wird, wie Sie in ausdrücklichen Attributwerten erwähnten? – notionquest
Können Sie die Abfrage durchführen und Ergebnisse mit der AWS-Konsole abrufen? – smcstewart
@notionquest: Der Fall scheint gut. Der betreffende Artikel wird als "Land": "Portugal" in der Datenbank gespeichert. – Sharjeel