question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(aws-lambda-nodejs): ICommandHooks requires all hooks to be implementated

See original GitHub issue

Reproduction Steps

    new lambda.NodejsFunction(this, "LambdaFunction", {
      bundling: {
        commandHooks: {
          afterBundling(inputDir: string, outputDir: string): string[] {
            return [`echo "hello world"`];
          },
        },
      },
    });

What did you expect to happen?

For this to be valid, and the equivalent of defining no commands for beforeBundling and beforeInstall.

What actually happened?

Type '{ afterBundling(inputDir: string, outputDir: string): string[]; }' is missing the following properties from type 'ICommandHooks': beforeBundling, beforeInstall

Environment

  • CDK CLI Version : 1.91.0
  • Framework Version: 1.91.0
  • Node.js Version: v14.15.1
  • OS : macOS Catalina
  • Language (Version): Typescript (4.2.3)

Other

Happy to provide a pull-request for this, looks very easy to fix. Unless I’m missing something we can just declare the functions as optional and then default them to the equivalent of () => [].


This is 🐛 Bug Report

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:3
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
icj217commented, Apr 20, 2022

Was able to figure out how to implement this in Python. The key step was creating an instance of the class and passing that into BundlingOptions

import typing
import builtins
import jsii
from aws_cdk import (
    aws_lambda_nodejs as njs,
)
​
@jsii.implements(njs.ICommandHooks)
class CustomCommandHooks:
​
    @jsii.member(jsii_name="afterBundling")
    def after_bundling(self, input_dir: builtins.str, output_dir: builtins.str) -> typing.List[builtins.str]:
        return []
​
    @jsii.member(jsii_name="beforeBundling")
    def before_bundling(self, input_dir: builtins.str, output_dir: builtins.str) -> typing.List[builtins.str]:
        return [f"cd {input_dir}", "yarn"]
​
    @jsii.member(jsii_name="beforeInstall")
    def before_install(self, input_dir: builtins.str, output_dir: builtins.str) -> typing.List[builtins.str]:
        return []

...


hooks = CustomCommandHooks()
​
options = njs.BundlingOptions(
        source_map=True,
        target="es2020",
        format=njs.OutputFormat.CJS,
        loader={".yaml": "file"},
        command_hooks=hooks)

@piotrekwitkowski FYI

1reaction
piotrekwitkowskicommented, Aug 3, 2021

A Python example how to use command_hooks would be greatly appreciated!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Amazon Lambda Node.js Library - AWS Documentation
The following hooks are available: beforeBundling : runs before all bundling commands. beforeInstall : runs before node modules installation.
Read more >
[lambda-nodejs] Deploy additional files alongside bundled ...
I want to be able to push up some additional files along with the bundled output. One way of doing this would be...
Read more >
@aws-cdk/aws-lambda-nodejs - npm
Start using @aws-cdk/aws-lambda-nodejs in your project by running `npm i ... to run additional commands by specifying the commandHooks prop:.
Read more >
Project-level configurations - Command Hooks - Amplify Docs
Use Command Hooks to execute custom scripts before, during, and after Amplify CLI commands (“amplify push”, “amplify api gql-compile”, and more).
Read more >
Webpack - Serverless Framework: Plugins
Integration of the lifecycles into the command invocations and hooks. The following list shows all lifecycles that are invoked/started by the plugin when ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found