Andrea Cosentino created CAMEL-24354:
----------------------------------------

             Summary: camel-aws2-lambda: updateFunction never sets the code 
source, so UpdateFunctionCode always fails
                 Key: CAMEL-24354
                 URL: https://issues.apache.org/jira/browse/CAMEL-24354
             Project: Camel
          Issue Type: Bug
          Components: camel-aws
            Reporter: Andrea Cosentino
             Fix For: 4.22.0


h3. Problem

In {{Lambda2Producer.updateFunction()}}, the default (non-{{pojoRequest}}) 
branch builds an {{UpdateFunctionCodeRequest}} but only ever sets 
{{functionName}} and (optionally) {{publish}}. It *validates* that a message 
body, {{CamelAwsLambdaS3Bucket}}, or {{CamelAwsLambdaS3Key}} is present and 
then discards them — it never calls {{zipFile(..)}}, {{s3Bucket(..)}}, 
{{s3Key(..)}} or {{s3ObjectVersion(..)}} on the builder.

{code:java}
UpdateFunctionCodeRequest.Builder builder = UpdateFunctionCodeRequest.builder();
builder.functionName(getEndpoint().getFunction());
if (ObjectHelper.isEmpty(body) && isEmpty(S3_BUCKET) && isEmpty(S3_KEY)) {
    throw new IllegalArgumentException("At least S3 bucket/S3 key or zip file 
must be specified");
}
// publish only
request = builder.build();   // <-- no code source ever set
{code}

AWS {{UpdateFunctionCode}} requires exactly one code source (ZipFile, or 
S3Bucket+S3Key, or ImageUri). The request built here has none, so the call is 
always rejected with {{InvalidParameterValueException: "Please provide a source 
for function code."}} The {{updateFunction}} operation is therefore unusable in 
the default mode. ({{pojoRequest=true}} is unaffected, since the caller 
supplies a complete request.)

Contrast {{createFunction()}}, which correctly assembles the code source from 
the 
{{CamelAwsLambdaS3Bucket}}/{{CamelAwsLambdaS3Key}}/{{CamelAwsLambdaS3ObjectVersion}}/{{CamelAwsLambdaZipFile}}
 headers and the body.

It went unnoticed because no unit test invokes the {{updateFunction}} route, 
and the test mock's {{updateFunctionCode}} echoes only the function name.

h3. Fix

Assemble the code source on the {{UpdateFunctionCodeRequest.Builder}} (which 
exposes {{zipFile}}/{{s3Bucket}}/{{s3Key}}/{{s3ObjectVersion}} directly) from 
the same headers/body as {{createFunction}}, and add a test that asserts the 
code source is present on the request.

Also fixes a minor copy-paste in {{deleteEventSourceMapping()}}: the validation 
reads the {{CamelAwsLambdaEventSourceMappingUuid}} header but throws "Event 
Source Arn must be specified" — the message should say UUID.

Affects main (4.22.0) and the 4.18.x / 4.14.x lines.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to