-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Support for AWS Lambda Function SDK V2 (#2130)
- Loading branch information
Showing
55 changed files
with
1,340 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
aws-sdk-v2/src/main/java/io/micronaut/aws/sdk/v2/service/lambda/LambdaClientFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright 2017-2024 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micronaut.aws.sdk.v2.service.lambda; | ||
|
||
import io.micronaut.aws.sdk.v2.service.AWSServiceConfiguration; | ||
import io.micronaut.aws.sdk.v2.service.AwsClientFactory; | ||
import io.micronaut.aws.ua.UserAgentProvider; | ||
import io.micronaut.context.annotation.Bean; | ||
import io.micronaut.context.annotation.Factory; | ||
import io.micronaut.context.annotation.Requires; | ||
import io.micronaut.core.annotation.Nullable; | ||
import jakarta.inject.Named; | ||
import jakarta.inject.Singleton; | ||
import software.amazon.awssdk.auth.credentials.AwsCredentialsProviderChain; | ||
import software.amazon.awssdk.http.SdkHttpClient; | ||
import software.amazon.awssdk.http.async.SdkAsyncHttpClient; | ||
import software.amazon.awssdk.regions.providers.AwsRegionProviderChain; | ||
import software.amazon.awssdk.services.lambda.LambdaAsyncClient; | ||
import software.amazon.awssdk.services.lambda.LambdaAsyncClientBuilder; | ||
import software.amazon.awssdk.services.lambda.LambdaClient; | ||
import software.amazon.awssdk.services.lambda.LambdaClientBuilder; | ||
|
||
/** | ||
* Factory that creates {@link LambdaClient} and {@link LambdaAsyncClient}. | ||
* @since 4.7.0 | ||
*/ | ||
@Factory | ||
class LambdaClientFactory extends AwsClientFactory<LambdaClientBuilder, LambdaAsyncClientBuilder, LambdaClient, LambdaAsyncClient> { | ||
/** | ||
* Constructor. | ||
* | ||
* @param credentialsProvider The credentials provider | ||
* @param regionProvider The region provider | ||
* @param userAgentProvider User-Agent Provider | ||
* @param awsServiceConfiguration AWS Service Configuration | ||
*/ | ||
protected LambdaClientFactory(AwsCredentialsProviderChain credentialsProvider, | ||
AwsRegionProviderChain regionProvider, | ||
@Nullable UserAgentProvider userAgentProvider, | ||
@Nullable @Named(LambdaClient.SERVICE_NAME) AWSServiceConfiguration awsServiceConfiguration) { | ||
super(credentialsProvider, regionProvider, userAgentProvider, awsServiceConfiguration); | ||
} | ||
|
||
@Override | ||
protected LambdaClientBuilder createSyncBuilder() { | ||
return LambdaClient.builder(); | ||
} | ||
|
||
@Override | ||
protected LambdaAsyncClientBuilder createAsyncBuilder() { | ||
return LambdaAsyncClient.builder(); | ||
} | ||
|
||
@Override | ||
@Singleton | ||
public LambdaClientBuilder syncBuilder(SdkHttpClient httpClient) { | ||
return super.syncBuilder(httpClient); | ||
} | ||
|
||
@Override | ||
@Bean(preDestroy = "close") | ||
@Singleton | ||
public LambdaClient syncClient(LambdaClientBuilder builder) { | ||
return super.syncClient(builder); | ||
} | ||
|
||
@Override | ||
@Singleton | ||
@Requires(beans = SdkAsyncHttpClient.class) | ||
public LambdaAsyncClientBuilder asyncBuilder(SdkAsyncHttpClient httpClient) { | ||
return super.asyncBuilder(httpClient); | ||
} | ||
|
||
@Override | ||
@Bean(preDestroy = "close") | ||
@Singleton | ||
@Requires(beans = SdkAsyncHttpClient.class) | ||
public LambdaAsyncClient asyncClient(LambdaAsyncClientBuilder builder) { | ||
return super.asyncClient(builder); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
aws-sdk-v2/src/main/java/io/micronaut/aws/sdk/v2/service/lambda/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright 2017-2024 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
/** | ||
* Lambda client factory. | ||
* @author Luis Duarte | ||
* @since 4.7.0 | ||
*/ | ||
@Requires(classes = {LambdaClient.class, LambdaAsyncClient.class}) | ||
@Configuration | ||
package io.micronaut.aws.sdk.v2.service.lambda; | ||
|
||
import io.micronaut.context.annotation.Configuration; | ||
import io.micronaut.context.annotation.Requires; | ||
import software.amazon.awssdk.services.lambda.LambdaAsyncClient; | ||
import software.amazon.awssdk.services.lambda.LambdaClient; |
20 changes: 20 additions & 0 deletions
20
aws-sdk-v2/src/test/groovy/io/micronaut/aws/sdk/v2/service/LambdaClientSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package io.micronaut.aws.sdk.v2.service | ||
|
||
import software.amazon.awssdk.services.lambda.LambdaAsyncClient | ||
import software.amazon.awssdk.services.lambda.LambdaClient | ||
|
||
class LambdaClientSpec extends ServiceClientSpec<LambdaClient, LambdaAsyncClient> { | ||
@Override | ||
protected String serviceName() { | ||
return LambdaClient.SERVICE_NAME | ||
} | ||
|
||
@Override | ||
protected LambdaClient getClient() { | ||
applicationContext.getBean(LambdaClient) | ||
} | ||
|
||
protected LambdaAsyncClient getAsyncClient() { | ||
applicationContext.getBean(LambdaAsyncClient) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
plugins { | ||
id("io.micronaut.build.internal.aws-module") | ||
} | ||
|
||
dependencies { | ||
api(projects.micronautAwsSdkV2) | ||
implementation(libs.awssdk.lambda) | ||
implementation(mn.reactor) | ||
api(mn.micronaut.function.client) | ||
testAnnotationProcessor(mn.micronaut.inject.java) | ||
testImplementation(mn.micronaut.inject.java) | ||
testImplementation(mnSerde.micronaut.serde.api) | ||
testImplementation(mn.micronaut.http.server.netty) | ||
testImplementation(mn.micronaut.function.web) | ||
testImplementation(mnGroovy.micronaut.function.groovy) | ||
testImplementation(mnGroovy.micronaut.runtime.groovy) | ||
testImplementation(platform(mnTestResources.boms.testcontainers)) | ||
testImplementation(libs.testcontainers) | ||
testImplementation(libs.testcontainers.localstack) | ||
testImplementation(libs.testcontainers.spock) | ||
testImplementation(libs.awssdk.iam) | ||
} | ||
micronautBuild { | ||
// new module, so no binary check | ||
binaryCompatibility { | ||
enabled.set(false) | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
...-aws-v2/src/main/java/io/micronaut/function/client/aws/v2/AwsInvokeRequestDefinition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Copyright 2017-2020 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.micronaut.function.client.aws.v2; | ||
|
||
import io.micronaut.context.annotation.EachProperty; | ||
import io.micronaut.context.annotation.Parameter; | ||
import io.micronaut.function.client.FunctionDefinition; | ||
|
||
/** | ||
* Builds an {@link AwsInvokeRequestDefinition} for each definition under {@code aws.lambda.functions}. | ||
* | ||
* @since 4.7.0 | ||
*/ | ||
@EachProperty(AwsInvokeRequestDefinition.AWS_LAMBDA_FUNCTIONS) | ||
public class AwsInvokeRequestDefinition implements FunctionDefinition { | ||
/** | ||
* Configuration prefix. | ||
*/ | ||
public static final String AWS_LAMBDA_FUNCTIONS = "aws.lambda.functions"; | ||
|
||
private final String name; | ||
|
||
private String functionName; | ||
|
||
private String qualifier; | ||
|
||
private String clientContext; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param name configured name from a property | ||
*/ | ||
public AwsInvokeRequestDefinition(@Parameter String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return this.name; | ||
} | ||
|
||
/** | ||
* | ||
* @return The name or ARN of the Lambda function, version, or alias. | ||
*/ | ||
public String getFunctionName() { | ||
return functionName; | ||
} | ||
|
||
/** | ||
* | ||
* @param functionName The name or ARN of the Lambda function, version, or alias. | ||
*/ | ||
public void setFunctionName(String functionName) { | ||
this.functionName = functionName; | ||
} | ||
|
||
/** | ||
* | ||
* @return Specify a version or alias to invoke a published version of the function. | ||
*/ | ||
public String getQualifier() { | ||
return qualifier; | ||
} | ||
|
||
/** | ||
* {@see software.amazon.awssdk.services.lambda.model.InvokeRequest#clientContext}. | ||
* @return Up to 3,583 bytes of base64-encoded data about the invoking client to pass to the function in the context object. | ||
*/ | ||
public String getClientContext() { | ||
return clientContext; | ||
} | ||
|
||
/** | ||
* {@see software.amazon.awssdk.services.lambda.model.InvokeRequest#qualifier}. | ||
* @param qualifier Specify a version or alias to invoke a published version of the function. | ||
*/ | ||
public void setQualifier(String qualifier) { | ||
this.qualifier = qualifier; | ||
} | ||
|
||
/** | ||
* | ||
* @param clientContext Up to 3,583 bytes of base64-encoded data about the invoking client to pass to the function in the context object. | ||
*/ | ||
public void setClientContext(String clientContext) { | ||
this.clientContext = clientContext; | ||
} | ||
} |
Oops, something went wrong.