This is an automated email from the ASF dual-hosted git repository.

oscerd pushed a commit to branch camel-4.14.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-4.14.x by this push:
     new b0b33f0fae5c [backport camel-4.14.x] CAMEL-24354: camel-aws2-lambda - 
updateFunction never sets the code source (#25356)
b0b33f0fae5c is described below

commit b0b33f0fae5cfe54aa6cab71ed07b0218dd3f373
Author: Andrea Cosentino <[email protected]>
AuthorDate: Wed Aug 5 14:25:19 2026 +0200

    [backport camel-4.14.x] CAMEL-24354: camel-aws2-lambda - updateFunction 
never sets the code source (#25356)
    
    CAMEL-24354: camel-aws2-lambda - updateFunction sends the code source so 
UpdateFunctionCode no longer fails
    
    Lambda2Producer.updateFunction() built an UpdateFunctionCodeRequest that 
only
    ever carried functionName and (optionally) publish: it validated that a 
body,
    S3 bucket, or S3 key was present and then discarded them, never setting
    zipFile/s3Bucket/s3Key/s3ObjectVersion. AWS UpdateFunctionCode requires a 
code
    source, so every call failed with InvalidParameterValueException and the
    operation was unusable in the default (non-pojoRequest) mode.
    
    Assemble the code source on the request builder from the same headers/body 
as
    createFunction (S3 bucket/key/object-version, the ZIP_FILE header path, and 
the
    message body), and add a test asserting the request carries it.
    
    Also corrects deleteEventSourceMapping's validation message, which read
    "Event Source Arn must be specified" although it validates the event source
    mapping UUID.
    
    Signed-off-by: Andrea Cosentino <[email protected]>
    Co-authored-by: Claude Opus 4.8 <[email protected]>
---
 .../component/aws2/lambda/Lambda2Producer.java     | 31 ++++++++++++++++++++--
 .../aws2/lambda/AmazonLambdaClientMock.java        |  3 +++
 .../component/aws2/lambda/LambdaProducerTest.java  | 23 ++++++++++++++++
 3 files changed, 55 insertions(+), 2 deletions(-)

diff --git 
a/components/camel-aws/camel-aws2-lambda/src/main/java/org/apache/camel/component/aws2/lambda/Lambda2Producer.java
 
b/components/camel-aws/camel-aws2-lambda/src/main/java/org/apache/camel/component/aws2/lambda/Lambda2Producer.java
index d3e6d0d54da9..c79d3f30752d 100644
--- 
a/components/camel-aws/camel-aws2-lambda/src/main/java/org/apache/camel/component/aws2/lambda/Lambda2Producer.java
+++ 
b/components/camel-aws/camel-aws2-lambda/src/main/java/org/apache/camel/component/aws2/lambda/Lambda2Producer.java
@@ -387,10 +387,37 @@ public class Lambda2Producer extends DefaultProducer {
 
             if (ObjectHelper.isEmpty(exchange.getIn().getBody())
                     && 
ObjectHelper.isEmpty(exchange.getIn().getHeader(Lambda2Constants.S3_BUCKET))
-                    && 
ObjectHelper.isEmpty(exchange.getIn().getHeader(Lambda2Constants.S3_KEY))) {
+                    && 
ObjectHelper.isEmpty(exchange.getIn().getHeader(Lambda2Constants.S3_KEY))
+                    && 
ObjectHelper.isEmpty(exchange.getIn().getHeader(Lambda2Constants.ZIP_FILE))) {
                 throw new IllegalArgumentException("At least S3 bucket/S3 key 
or zip file must be specified");
             }
 
+            if 
(ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.S3_BUCKET)))
 {
+                String s3Bucket = 
exchange.getIn().getHeader(Lambda2Constants.S3_BUCKET, String.class);
+                builder.s3Bucket(s3Bucket);
+            }
+
+            if 
(ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.S3_KEY))) {
+                String s3Key = 
exchange.getIn().getHeader(Lambda2Constants.S3_KEY, String.class);
+                builder.s3Key(s3Key);
+            }
+
+            if 
(ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.S3_OBJECT_VERSION)))
 {
+                String s3ObjectVersion = 
exchange.getIn().getHeader(Lambda2Constants.S3_OBJECT_VERSION, String.class);
+                builder.s3ObjectVersion(s3ObjectVersion);
+            }
+
+            if 
(ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.ZIP_FILE)))
 {
+                String zipFile = 
exchange.getIn().getHeader(Lambda2Constants.ZIP_FILE, String.class);
+                File fileLocalPath = new File(zipFile);
+                try (FileInputStream inputStream = new 
FileInputStream(fileLocalPath)) {
+                    builder.zipFile(SdkBytes.fromInputStream(inputStream));
+                }
+            }
+            if (ObjectHelper.isNotEmpty(exchange.getIn().getBody())) {
+                
builder.zipFile(SdkBytes.fromByteBuffer(exchange.getIn().getBody(ByteBuffer.class)));
+            }
+
             if 
(ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.PUBLISH))) 
{
                 Boolean publish = 
exchange.getIn().getHeader(Lambda2Constants.PUBLISH, Boolean.class);
                 builder.publish(publish);
@@ -449,7 +476,7 @@ public class Lambda2Producer extends DefaultProducer {
             if 
(ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.EVENT_SOURCE_UUID)))
 {
                 
builder.uuid(exchange.getIn().getHeader(Lambda2Constants.EVENT_SOURCE_UUID, 
String.class));
             } else {
-                throw new IllegalArgumentException("Event Source Arn must be 
specified");
+                throw new IllegalArgumentException("Event Source UUID must be 
specified");
             }
             request = builder.build();
         }
diff --git 
a/components/camel-aws/camel-aws2-lambda/src/test/java/org/apache/camel/component/aws2/lambda/AmazonLambdaClientMock.java
 
b/components/camel-aws/camel-aws2-lambda/src/test/java/org/apache/camel/component/aws2/lambda/AmazonLambdaClientMock.java
index 589a6f0b1884..28be5d847d64 100644
--- 
a/components/camel-aws/camel-aws2-lambda/src/test/java/org/apache/camel/component/aws2/lambda/AmazonLambdaClientMock.java
+++ 
b/components/camel-aws/camel-aws2-lambda/src/test/java/org/apache/camel/component/aws2/lambda/AmazonLambdaClientMock.java
@@ -73,6 +73,8 @@ import 
software.amazon.awssdk.services.lambda.model.UpdateFunctionCodeResponse;
 
 public class AmazonLambdaClientMock implements LambdaClient {
 
+    public UpdateFunctionCodeRequest updateFunctionCodeRequest;
+
     public AmazonLambdaClientMock() {
     }
 
@@ -291,6 +293,7 @@ public class AmazonLambdaClientMock implements LambdaClient 
{
 
     @Override
     public UpdateFunctionCodeResponse 
updateFunctionCode(UpdateFunctionCodeRequest updateFunctionCodeRequest) {
+        this.updateFunctionCodeRequest = updateFunctionCodeRequest;
         UpdateFunctionCodeResponse.Builder result = 
UpdateFunctionCodeResponse.builder();
 
         result.functionName(updateFunctionCodeRequest.functionName());
diff --git 
a/components/camel-aws/camel-aws2-lambda/src/test/java/org/apache/camel/component/aws2/lambda/LambdaProducerTest.java
 
b/components/camel-aws/camel-aws2-lambda/src/test/java/org/apache/camel/component/aws2/lambda/LambdaProducerTest.java
index 0645e21fec8e..0ee70c6f0373 100644
--- 
a/components/camel-aws/camel-aws2-lambda/src/test/java/org/apache/camel/component/aws2/lambda/LambdaProducerTest.java
+++ 
b/components/camel-aws/camel-aws2-lambda/src/test/java/org/apache/camel/component/aws2/lambda/LambdaProducerTest.java
@@ -89,6 +89,29 @@ public class LambdaProducerTest extends CamelTestSupport {
         assertNotNull(result.codeSha256());
     }
 
+    @Test
+    public void lambdaUpdateFunctionTest() throws Exception {
+
+        Exchange exchange = template.send("direct:updateFunction", 
ExchangePattern.InOut, new Processor() {
+            @Override
+            public void process(Exchange exchange) throws Exception {
+                ClassLoader classLoader = getClass().getClassLoader();
+                File file = new File(
+                        
classLoader.getResource("org/apache/camel/component/aws2/lambda/function/node/GetHelloWithName.zip")
+                                .getFile());
+                FileInputStream inputStream = new FileInputStream(file);
+                exchange.getIn().setBody(inputStream);
+            }
+        });
+
+        assertNotNull(exchange.getMessage().getBody());
+        // the fix: the code source (the zip taken from the body) must 
actually reach the request,
+        // otherwise AWS rejects UpdateFunctionCode with "Please provide a 
source for function code."
+        assertNotNull(clientMock.updateFunctionCodeRequest);
+        assertEquals("GetHelloWithName", 
clientMock.updateFunctionCodeRequest.functionName());
+        assertNotNull(clientMock.updateFunctionCodeRequest.zipFile());
+    }
+
     @Test
     public void lambdaDeleteFunctionTest() {
 

Reply via email to