functionless: table.query is not a function
I tried using Table inside a Function, and got this error. The generated code seems to be missing every method. Did I do this right?
ddbTable.addGlobalSecondaryIndex({
indexName: 'GSI1',
partitionKey: { name: 'PK', type: aws_dynamodb.AttributeType.STRING },
sortKey: { name: 'SK', type: aws_dynamodb.AttributeType.STRING },
projectionType: aws_dynamodb.ProjectionType.ALL,
});
const table = new Table<ITable, 'PK', any>(ddbTable);
const defaultAuthFunction = new Function<AuthContext, AuthResponse>(
this,
'LambdaAuthorizer',
{
logRetention: 14,
},
async (c) => {
const apiKey = c.authorizationToken;
// Look up the account using the auth token.
const item = table.query({
index: 'GSI1',
query: {
expression: 'PK = :pk',
expressionValues: { ':pk': { S: apiKey } },
},
}).items[0];
// If it exists and it's a valid account, allow request.
if (item?.entityType === 'Account') {
const accountId = item.Id;
return {
isAuthorized: true,
// Add account id and api key into the resolver context.
resolverContext: { accountId, apiKey },
deniedFields: [],
};
}
//
return {
isAuthorized: false,
resolverContext: {},
deniedFields: [],
};
},
);
And here is the part of the generated code with the __table object.
var __table = {};
var __table_query = {};
__table_query.kind = "Table.query";
__table_query.unhandledContext = __f5;
var __table_query_native = {call: undefined, preWarm: undefined};
__table_query.native = __table_query_native;
__table.query = __table_query;
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (6 by maintainers)
My list right now is…
Another big breaking change like #132 can follow async.
We should also prioritize these two issues. It’s clear that new users are going to quickly stumble into these same problems - appsync-only resolvers in lambda and incomplete dynamo index support.
https://github.com/functionless/functionless/issues/136
https://github.com/functionless/functionless/issues/132
Table.* Doesn’t work in function right now.
You can use
$AWS.DynamoDB.Query()The reason is table.* Use the app sync contracts right now, we have a ticket to resolve this, but it’s non trivial to recreate the next token and other parts of the app sync to dynamo contract.
The larger issue is that lambda doesn’t give an error at compile/synth time which I’ll look into.