Skip to content
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(type-safe-api): generate lambda handler stubs based on model trait #537

Merged
merged 1 commit into from
Aug 16, 2023

Conversation

cogwirrel
Copy link
Member

This change adds a new configuration option handlers which allows users to opt in to generating lambda handler projects for java, python, and/or typescript, ready-configured with packaging tasks for use in a lambda function.

Handler stubs are generated for operations annotated with the @handler trait in Smithy (or the x-handler vendor extension in OpenAPI), only generating the handler stubs for the chosen language for each operation. Documentation to come once this feature has been further fleshed out!

For now, as a very quick reference, here's how you'd reference a lambda in each language from these packages:

    new Api(this, 'api', {
      defaultAuthorizer: Authorizers.iam(),
      integrations: {
        someTypescriptOp: {
          integration: Integrations.lambda(new Function(this, 'someTypescriptOp', {
            runtime: Runtime.NODEJS_18_X,
            code: Code.fromAsset('../api/handlers/typescript/dist/lambda/some-typescript-op'),
            handler: 'index.handler',
          })),
        },
        someJavaOp: {
          integration: Integrations.lambda(new Function(this, 'someJavaOp', {
            runtime: Runtime.JAVA_17,
            code: Code.fromAsset('../api/handlers/java/dist/java/com/generated/api/api-java-handlers/0.0.0/api-java-handlers-0.0.0.jar'),
            handler: 'com.generated.api.apijavahandlers.handlers.SomeJavaOpHandler',
          })),
        },
        somePythonOp: {
          integration: Integrations.lambda(new Function(this, 'somePythonOp', {
            runtime: Runtime.PYTHON_3_11,
            code: Code.fromAsset('../api/handlers/python/dist/lambda'),
            handler: 'api_python_handlers.some_python_op.handler',
          })),
        },
      },
    });

Once the handlers have been initially generated, they are never overwritten (much like projen sample code, except generated at build time). If users move or rename generated handlers, they will be generated again - so if not sticking to the default project structure it's recommended to add the @handler trait, build, rename/refactor, remove the @handler trait, and continue.

Coming soon:

  • Generate tests
  • Generate default interceptors

This change adds a new configuration option `handlers` which allows users to opt in to generating
lambda handler projects for java, python, and/or typescript, ready-configured with packaging tasks
for use in a lambda function. Handler stubs are generated for operations annotated with the @handler
trait in Smithy (or the x-handler vendor extension in OpenAPI), only generating the handler stubs
for the chosen language for each operation. Documentation to come once this feature has been further
fleshed out.
Copy link
Contributor

@agdimech agdimech left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work buddy - this is looking fantastic, can't wait to try it!

@agdimech agdimech merged commit 16633b6 into mainline Aug 16, 2023
3 checks passed
@agdimech agdimech deleted the feat/handler-gen branch August 16, 2023 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants