micronaut-projects / micronaut-starter

Generates Micronaut applications
Apache License 2.0
211 stars 96 forks source link

AWS Lambda with SnapStart and CDK #2042

Closed msailes closed 11 months ago

msailes commented 1 year ago

Thanks for reporting an issue, please review the task list below before submitting the issue. Your issue report will be closed if the issue is incomplete and the below tasks not completed.

NOTE: If you are unsure about something and the issue is more of a question a better place to ask questions is on Stack Overflow (http://stackoverflow.com/tags/micronaut) or Gitter (https://gitter.im/micronautfw/). DO NOT use the issue tracker to ask questions.

Description

The CDK has been updated (v2.94.0) recently to provide better support for Lambda SnapStart.

At the moment you generate this

    @if (features.contains("snapstart")) {
        IConstruct defaultChild = function.getNode().getDefaultChild();
        if (defaultChild instanceof CfnFunction) {
            CfnFunction cfnFunction = (CfnFunction) defaultChild;
            cfnFunction.setSnapStart(CfnFunction.SnapStartProperty.builder()
                .applyOn("PublishedVersions")
                .build());
        }
    }

It can be replaced with

      Function lambdaFn = Function.Builder.create(this,"ScheduledFunction")
              ...
              .snapStart(SnapStartConf.ON_PUBLISHED_VERSIONS)
              ...
              .build();

Task List

Steps to Reproduce

  1. mn create-app --build=gradle --jdk=17 --lang=java --test=junit --features=aws-lambda,aws-cdk com.example.demo

Expected Behaviour

AppStack.java should have the updated code

Actual Behaviour

AppStack.java will have the old style code

Environment Information

Example Application

wetted commented 1 year ago

      Function lambdaFn = Function.Builder.create(this,"ScheduledFunction")
              ...
              .snapStart(SnapStartConf.ON_PUBLISHED_VERSIONS)
              ...
              .build();

@sdelamo @msailes

I'm not clear about the ellipses here. Is there something we should be generating in their place? I assume it just indicates a developer can add more builder calls as desired.

msailes commented 1 year ago

Sorry @wetted,

Micronaut is already generating a Function with other configuration. The .snapStart(SnapStartConf.ON_PUBLISHED_VERSIONS) bit would be added to whatever you already had.

Thanks,

wetted commented 1 year ago

@msailes OK. I hope I understand. micronaut-starter features is more my expertise than AWS. I opened a PR with the change I think it needs, based on your original description.

Edit: I see now where my confusion lies. Sorry for the noise.

msailes commented 1 year ago

No problem, @sdelamo can help organize a video call if needed.

wetted commented 1 year ago

No problem, @sdelamo can help organize a video call if needed.

I think I have it now. I pushed a change to the PR to correct my confusion. Feel free to review/comment/suggest. Thanks for pointing these out so we can improve things. :)