-
Notifications
You must be signed in to change notification settings - Fork 72
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: Add lamda data client support #2224
feat: Add lamda data client support #2224
Conversation
🦋 Changeset detectedLatest commit: 2b7b02f The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
packages/backend-function/src/function_data_config_generator.ts
Outdated
Show resolved
Hide resolved
packages/backend-function/src/runtime/get_amplify_clients_configuration.ts
Outdated
Show resolved
Hide resolved
517f304
to
eb41f64
Compare
packages/backend-function/src/runtime/get_amplify_clients_configuration.ts
Show resolved
Hide resolved
packages/backend-function/src/function_data_config_generator.ts
Outdated
Show resolved
Hide resolved
packages/backend-function/src/runtime/get_amplify_clients_configuration.ts
Outdated
Show resolved
Hide resolved
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
import * as __export__runtime from './runtime/index.js'; | ||
// eslint-disable-next-line @typescript-eslint/naming-convention | ||
import * as __export__get_amplify_clients_configuration from './runtime/get_amplify_clients_configuration.js'; | ||
|
||
/* | ||
Api-extractor does not ([yet](https://github.com/microsoft/rushstack/issues/1596)) support multiple package entry points | ||
Because this package has a submodule export, we are working around this issue by including that export here and directing api-extract to this entry point instead | ||
This allows api-extractor to pick up the submodule exports in its analysis | ||
*/ | ||
export { __export__runtime, __export__get_amplify_clients_configuration }; |
This comment was marked as resolved.
This comment was marked as resolved.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The changes look good to me. The only missing part is an e2e test where we assert that lambda function can access the data client at runtime. E.g.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
packages/backend-function/src/runtime/get_amplify_clients_configuration.ts
Show resolved
Hide resolved
1ebc7f0
to
bf16475
Compare
bf16475
to
d1dec7f
Compare
This comment was marked as resolved.
This comment was marked as resolved.
packages/integration-tests/src/test-projects/data-and-function/amplify/backend.ts
Fixed
Show fixed
Hide fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Co-authored-by: Kamil Sobol <[email protected]>
packages/integration-tests/src/test-project-setup/data_and_function_project.ts
Outdated
Show resolved
Hide resolved
...tegration-tests/src/test-projects/data-and-function/amplify/functions/noop-import/handler.ts
Outdated
Show resolved
Hide resolved
…a/function-runtime-config
packages/integration-tests/src/test-projects/data_access_from_function/amplify/backend.ts
Dismissed
Show dismissed
Hide dismissed
throw new Error('Data and function project must include api_key'); | ||
} | ||
|
||
// const dataUrl = clientConfig.data?.url; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is not good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean the commented code (removed), or is there something about the error thrown validating the api key that isn't good?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean the commented code (removed)
Yes.
packages/integration-tests/src/test-project-setup/data_access_from_function_project.ts
Outdated
Show resolved
Hide resolved
packages/integration-tests/src/test-project-setup/data_access_from_function_project.ts
Outdated
Show resolved
Hide resolved
await this.assertDataFunctionCallSucceeds(apolloClient); | ||
await this.assertNoopWithImportCallSucceeds(apolloClient); | ||
} | ||
|
||
private assertDataFunctionCallSucceeds = async ( | ||
apolloClient: ApolloClient<NormalizedCacheObject> | ||
): Promise<void> => { | ||
const response = await apolloClient.query<number>({ | ||
query: gql` | ||
query todoCount { | ||
todoCount | ||
} | ||
`, | ||
variables: {}, | ||
}); | ||
|
||
assert.deepEqual(response.data, { todoCount: 0 }); | ||
}; | ||
|
||
private assertNoopWithImportCallSucceeds = async ( | ||
apolloClient: ApolloClient<NormalizedCacheObject> | ||
): Promise<void> => { | ||
const response = await apolloClient.query<number>({ | ||
query: gql` | ||
query noopImport { | ||
noopImport | ||
} | ||
`, | ||
variables: {}, | ||
}); | ||
|
||
assert.deepEqual(response.data, { noopImport: 'STATIC TEST RESPONSE' }); | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't seem to see any code that would call the lambda.
If the feature is about lambda accessing appsync, we should be invoking lambda and asseserting that lambda intracted with appsync.
The test as is doesn't prove that lambda is working.
Some ideas how to test lambda can be found here - we assert that lambda interacts with s3 bucket there, similar strategy can be applied here for appsync.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both of these tests call a query, which each call a lambda and the response assertions are specific to the lambda being called (todoCount and noopImport).
I considered testing the lambda's in isolation (without wiring these calls through AppSync query calls), but that use-case is a simpler subset of the use-cases covered by these tests.
Can you help me understand the coverage gap that needs to be filled?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. There's no coverage gap then.
Can you add JSDoc comment to both private assert...
methods explaining that they indeed call the lambda and how ? For the reader it's not obvious that GQL calls translate to lambda invocations here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood. JSDoc added
Problem
Users would like to use the Gen2 data client interface to access their APIs from application functions (lambda's).
Our docs offer instructions on this experience, which stop short of indicating how the customer should provide the model introspection schema needed to make the whole experience work.
Changes
resource
permissions to the data schemaimport { getAmplifyClientsConfiguration } from "@aws-amplify/backend/function/runtime";
Example:
amplify/functions/todo-count/handler.ts
Corresponding docs PR, if applicable:
aws-amplify/docs#8096
Validation
S3Client
Checklist
run-e2e
label set.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.