Hi!
First of all, best tutorial I’ve ever completed and it’s saved my life, I understand so much more of AWS than I did before.
I’m trying to push the app a bit further and list all the notes from all users (basically the contents of the bucket) which i thought would be simple as I could query the table but without the KeyConditionExpression and ExpressionAttributeValues, like below in a file named listall.js:
import { success, failure } from "./libs/response-lib";
export async function main(event, context, callback) {
const params = {
TableName: "MY_TABLE_NAME",
// 'KeyConditionExpression' defines the condition for the query
// - 'userId = :userId': only return items with matching 'userId'
// partition key
// 'ExpressionAttributeValues' defines the value in the condition
// - ':userId': defines 'userId' to be Identity Pool identity id
// of the authenticated user
// KeyConditionExpression: "userId = :userId",
ExpressionAttributeValues: {
":userId": event.requestContext.identity.cognitoIdentityId
}
};
try {
const result = await dynamoDbLib.call("query", params);
// Return the matching list of items in response body
callback(null, success(result.Items));
} catch (e) {
callback(null, failure({ status: false }));
console.log('wtf');
}
}
My additions to my severless.yml below the ‘list’:
# Defines an HTTP API endpoint that calls the main function in list.js
# - path: url path is /feedsall
# - method: GET request
handler: listall.main
events:
- http:
path: feedsall
method: get
cors: true
authorizer: aws_iam
I’ve also added a different authenticated role in Federated Identities section:
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"mobileanalytics:PutEvents",
"cognito-sync:*",
"cognito-identity:*"
],
"Resource": [
"*"
]
},
{
"Effect": "Allow",
"Action": [
"s3:*"
],
"Resource": [
"arn:aws:s3:::MY_TABLE_NAME/private/${cognito-identity.amazonaws.com:sub}/*"
]
},
{
"Effect": "Allow",
"Action": [
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::MY_TABLE_NAME/*"
]
},
{
"Effect": "Allow",
"Action": [
"execute-api:Invoke"
],
"Resource": [
"arn:aws:execute-api:eu-west-1:*:BLABLABLA/*"
]
}
]
}
However I’ve been getting a 500 error code. Any help would b greatly appreciated
(error code, when i put “serverless invoke local --function listall --path mocks/list-event.json” in the terminal: )
"statusCode": 500,
"headers": {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Credentials": true
},
"body": "{\"status\":false}"
}