Skip to content

Commit b1389bb

Browse files
authored
Add Support for AWS Lambda Function SDK V2 (#2130)
1 parent d1df556 commit b1389bb

File tree

55 files changed

+1340
-105
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1340
-105
lines changed

aws-sdk-v2/build.gradle.kts

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ dependencies {
2424
compileOnly(libs.awssdk.secretsmanager)
2525
compileOnly(libs.awssdk.servicediscovery)
2626
compileOnly(libs.awssdk.cloudwatchlogs)
27+
compileOnly(libs.awssdk.lambda)
2728

2829
// Tests
2930
testAnnotationProcessor(mn.micronaut.inject.java)
@@ -41,6 +42,7 @@ dependencies {
4142
testImplementation(libs.awssdk.sqs)
4243
testImplementation(libs.awssdk.ssm)
4344
testImplementation(libs.awssdk.rekognition)
45+
testImplementation(libs.awssdk.lambda)
4446
testRuntimeOnly(libs.jcl.over.slf4j)
4547

4648
testRuntimeOnly(mn.snakeyaml)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright 2017-2024 original authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.micronaut.aws.sdk.v2.service.lambda;
17+
18+
import io.micronaut.aws.sdk.v2.service.AWSServiceConfiguration;
19+
import io.micronaut.aws.sdk.v2.service.AwsClientFactory;
20+
import io.micronaut.aws.ua.UserAgentProvider;
21+
import io.micronaut.context.annotation.Bean;
22+
import io.micronaut.context.annotation.Factory;
23+
import io.micronaut.context.annotation.Requires;
24+
import io.micronaut.core.annotation.Nullable;
25+
import jakarta.inject.Named;
26+
import jakarta.inject.Singleton;
27+
import software.amazon.awssdk.auth.credentials.AwsCredentialsProviderChain;
28+
import software.amazon.awssdk.http.SdkHttpClient;
29+
import software.amazon.awssdk.http.async.SdkAsyncHttpClient;
30+
import software.amazon.awssdk.regions.providers.AwsRegionProviderChain;
31+
import software.amazon.awssdk.services.lambda.LambdaAsyncClient;
32+
import software.amazon.awssdk.services.lambda.LambdaAsyncClientBuilder;
33+
import software.amazon.awssdk.services.lambda.LambdaClient;
34+
import software.amazon.awssdk.services.lambda.LambdaClientBuilder;
35+
36+
/**
37+
* Factory that creates {@link LambdaClient} and {@link LambdaAsyncClient}.
38+
* @since 4.7.0
39+
*/
40+
@Factory
41+
class LambdaClientFactory extends AwsClientFactory<LambdaClientBuilder, LambdaAsyncClientBuilder, LambdaClient, LambdaAsyncClient> {
42+
/**
43+
* Constructor.
44+
*
45+
* @param credentialsProvider The credentials provider
46+
* @param regionProvider The region provider
47+
* @param userAgentProvider User-Agent Provider
48+
* @param awsServiceConfiguration AWS Service Configuration
49+
*/
50+
protected LambdaClientFactory(AwsCredentialsProviderChain credentialsProvider,
51+
AwsRegionProviderChain regionProvider,
52+
@Nullable UserAgentProvider userAgentProvider,
53+
@Nullable @Named(LambdaClient.SERVICE_NAME) AWSServiceConfiguration awsServiceConfiguration) {
54+
super(credentialsProvider, regionProvider, userAgentProvider, awsServiceConfiguration);
55+
}
56+
57+
@Override
58+
protected LambdaClientBuilder createSyncBuilder() {
59+
return LambdaClient.builder();
60+
}
61+
62+
@Override
63+
protected LambdaAsyncClientBuilder createAsyncBuilder() {
64+
return LambdaAsyncClient.builder();
65+
}
66+
67+
@Override
68+
@Singleton
69+
public LambdaClientBuilder syncBuilder(SdkHttpClient httpClient) {
70+
return super.syncBuilder(httpClient);
71+
}
72+
73+
@Override
74+
@Bean(preDestroy = "close")
75+
@Singleton
76+
public LambdaClient syncClient(LambdaClientBuilder builder) {
77+
return super.syncClient(builder);
78+
}
79+
80+
@Override
81+
@Singleton
82+
@Requires(beans = SdkAsyncHttpClient.class)
83+
public LambdaAsyncClientBuilder asyncBuilder(SdkAsyncHttpClient httpClient) {
84+
return super.asyncBuilder(httpClient);
85+
}
86+
87+
@Override
88+
@Bean(preDestroy = "close")
89+
@Singleton
90+
@Requires(beans = SdkAsyncHttpClient.class)
91+
public LambdaAsyncClient asyncClient(LambdaAsyncClientBuilder builder) {
92+
return super.asyncClient(builder);
93+
}
94+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2017-2024 original authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
/**
17+
* Lambda client factory.
18+
* @author Luis Duarte
19+
* @since 4.7.0
20+
*/
21+
@Requires(classes = {LambdaClient.class, LambdaAsyncClient.class})
22+
@Configuration
23+
package io.micronaut.aws.sdk.v2.service.lambda;
24+
25+
import io.micronaut.context.annotation.Configuration;
26+
import io.micronaut.context.annotation.Requires;
27+
import software.amazon.awssdk.services.lambda.LambdaAsyncClient;
28+
import software.amazon.awssdk.services.lambda.LambdaClient;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package io.micronaut.aws.sdk.v2.service
2+
3+
import software.amazon.awssdk.services.lambda.LambdaAsyncClient
4+
import software.amazon.awssdk.services.lambda.LambdaClient
5+
6+
class LambdaClientSpec extends ServiceClientSpec<LambdaClient, LambdaAsyncClient> {
7+
@Override
8+
protected String serviceName() {
9+
return LambdaClient.SERVICE_NAME
10+
}
11+
12+
@Override
13+
protected LambdaClient getClient() {
14+
applicationContext.getBean(LambdaClient)
15+
}
16+
17+
protected LambdaAsyncClient getAsyncClient() {
18+
applicationContext.getBean(LambdaAsyncClient)
19+
}
20+
}
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
plugins {
2+
id("io.micronaut.build.internal.aws-module")
3+
}
4+
5+
dependencies {
6+
api(projects.micronautAwsSdkV2)
7+
implementation(libs.awssdk.lambda)
8+
implementation(mn.reactor)
9+
api(mn.micronaut.function.client)
10+
testAnnotationProcessor(mn.micronaut.inject.java)
11+
testImplementation(mn.micronaut.inject.java)
12+
testImplementation(mnSerde.micronaut.serde.api)
13+
testImplementation(mn.micronaut.http.server.netty)
14+
testImplementation(mn.micronaut.function.web)
15+
testImplementation(mnGroovy.micronaut.function.groovy)
16+
testImplementation(mnGroovy.micronaut.runtime.groovy)
17+
testImplementation(platform(mnTestResources.boms.testcontainers))
18+
testImplementation(libs.testcontainers)
19+
testImplementation(libs.testcontainers.localstack)
20+
testImplementation(libs.testcontainers.spock)
21+
testImplementation(libs.awssdk.iam)
22+
}
23+
micronautBuild {
24+
// new module, so no binary check
25+
binaryCompatibility {
26+
enabled.set(false)
27+
}
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
/*
2+
* Copyright 2017-2020 original authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.micronaut.function.client.aws.v2;
17+
18+
import io.micronaut.context.annotation.EachProperty;
19+
import io.micronaut.context.annotation.Parameter;
20+
import io.micronaut.function.client.FunctionDefinition;
21+
22+
/**
23+
* Builds an {@link AwsInvokeRequestDefinition} for each definition under {@code aws.lambda.functions}.
24+
*
25+
* @since 4.7.0
26+
*/
27+
@EachProperty(AwsInvokeRequestDefinition.AWS_LAMBDA_FUNCTIONS)
28+
public class AwsInvokeRequestDefinition implements FunctionDefinition {
29+
/**
30+
* Configuration prefix.
31+
*/
32+
public static final String AWS_LAMBDA_FUNCTIONS = "aws.lambda.functions";
33+
34+
private final String name;
35+
36+
private String functionName;
37+
38+
private String qualifier;
39+
40+
private String clientContext;
41+
42+
/**
43+
* Constructor.
44+
*
45+
* @param name configured name from a property
46+
*/
47+
public AwsInvokeRequestDefinition(@Parameter String name) {
48+
this.name = name;
49+
}
50+
51+
@Override
52+
public String getName() {
53+
return this.name;
54+
}
55+
56+
/**
57+
*
58+
* @return The name or ARN of the Lambda function, version, or alias.
59+
*/
60+
public String getFunctionName() {
61+
return functionName;
62+
}
63+
64+
/**
65+
*
66+
* @param functionName The name or ARN of the Lambda function, version, or alias.
67+
*/
68+
public void setFunctionName(String functionName) {
69+
this.functionName = functionName;
70+
}
71+
72+
/**
73+
*
74+
* @return Specify a version or alias to invoke a published version of the function.
75+
*/
76+
public String getQualifier() {
77+
return qualifier;
78+
}
79+
80+
/**
81+
* {@see software.amazon.awssdk.services.lambda.model.InvokeRequest#clientContext}.
82+
* @return Up to 3,583 bytes of base64-encoded data about the invoking client to pass to the function in the context object.
83+
*/
84+
public String getClientContext() {
85+
return clientContext;
86+
}
87+
88+
/**
89+
* {@see software.amazon.awssdk.services.lambda.model.InvokeRequest#qualifier}.
90+
* @param qualifier Specify a version or alias to invoke a published version of the function.
91+
*/
92+
public void setQualifier(String qualifier) {
93+
this.qualifier = qualifier;
94+
}
95+
96+
/**
97+
*
98+
* @param clientContext Up to 3,583 bytes of base64-encoded data about the invoking client to pass to the function in the context object.
99+
*/
100+
public void setClientContext(String clientContext) {
101+
this.clientContext = clientContext;
102+
}
103+
}

0 commit comments

Comments
 (0)