Skip to content

AWS event loop not started when running as a Container Image #1021

@martypitt

Description

@martypitt

Describe the bug
The goal:

  • Build a Native Image (using Spring Boot native)
  • Deploy as a Lambda Function, using a Container Image (deployed to ECR, rather than uploaded directly)

Issue:

When deployed in this fashion, the Spring Boot app starts OK, but fails to collect the event from AWS, so ultimately times out and is shut down.

Root cause:
When deployed as a container image, there are a number of issues that prevent the CustomRuntimeInitializer from bootstrapping the event loop, and the event loop from functioning:

isCustomRuntime expects _HANDLER variable

	private boolean isCustomRuntime(Environment environment) {
		String handler = environment.getProperty("_HANDLER");
		if (StringUtils.hasText(handler)) {

This is designed to work when the Lambda image is uploaded, and the handler has been configured. When running with container images, this isn't an option.

Also, manually setting the env variable isn't an option either, as AWS doesn't allow env varaibles beginning with an underscore.

Requires spring.cloud.function.web.export.enabled disabled

This isn't really a bug, but it wasn't obvious without reading the code that spring.cloud.function.web.export.enabled must be set to false. (See CustomRuntimeInitializer::isWebExportEnabled)

**CustomRuntimeEventLoop required DEFAULT_HANDLER set:

This isn't really a bug either, but required digging into the code.

In order to get function execution working, I had to set and env var of DEFAULT_HANDLER with the name of the function.

Workaround

In order to get this working, I manually configured a CustomRuntimeEventLoop:

    @Bean
    fun awsEventLoop(context: ConfigurableApplicationContext): CustomRuntimeEventLoop {
        return CustomRuntimeEventLoop(context)
    }

I also set the env var of DEFAULT_HANDLER to the name of the function I wanted to invoke within AWS.

Sample
There's a working example of this issue here

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions