davsclaus opened a new pull request, #3235:
URL: https://github.com/apache/camel-kamelets/pull/3235

   Part of #3170: `aws-lambda-sink`, `aws-ec2-sink` and 
`aws-secrets-manager-sink` can do more than their one operation, 
`aws-translate-action` can detect the language of each message and apply custom 
terminologies, and `aws-polly-sink` can apply pronunciation lexicons.
   
   ### The options
   
   | Kamelet | Option | Template mapping | What it does |
   |---|---|---|---|
   | `aws-lambda-sink` | `operation` | `operation: "{{?operation}}"` | 
`invokeFunction` (what it does today), `getFunction`, 
`getFunctionConfiguration`, `listVersions`, `listAliases`, `publishVersion`, 
`listFunctions`. Each acts on the function in `function`; only `invokeFunction` 
uses the body. |
   | `aws-ec2-sink` | `operation` | `operation: "{{operation}}"`, `default: 
describeInstancesStatus` | `describeInstancesStatus` (today's), 
`describeInstances`, `startInstances`, `stopInstances`, `rebootInstances`, on 
the instances of the `instanceIds` header. |
   | `aws-secrets-manager-sink` | `operation` | `operation: "{{operation}}"`, 
`default: createSecret` | `createSecret` (today's), `updateSecret` (the body 
becomes the new value of the secret in `secretId`, as a new version), 
`getSecret` (the value of the secret in `secretId` goes into the body). |
   | `aws-secrets-manager-sink` | `secretId` | a `choice` on the operation: for 
`updateSecret` and `getSecret`, `setHeader` `CamelAwsSecretsManagerSecretId` to 
the constant `{{?secretId}}`, or `throwException` when it is empty | The name 
or ARN of the secret that `updateSecret` and `getSecret` work on; required for 
them, not used by `createSecret`. |
   | `aws-secrets-manager-sink` | `binaryPayload` | `binaryPayload: 
"{{?binaryPayload}}"` | `createSecret` and `updateSecret` store the bytes of 
the body as `SecretBinary` instead of `SecretString`. |
   | `aws-translate-action` | `autodetectSourceLanguage` | 
`&autodetectSourceLanguage={{?autodetectSourceLanguage}}` | Amazon Translate 
detects the language of each message (`SourceLanguageCode: auto`). |
   | `aws-translate-action` | `terminologyNames` | a `choice` that, only when 
the option is set, sets `CamelAwsTranslateTerminologyNames` to 
`${split('{{?terminologyNames}}',',')}` | Applies custom terminologies. |
   | `aws-polly-sink` | `lexiconNames` | `lexiconNames: "{{?lexiconNames}}"` | 
Applies pronunciation lexicons stored in Polly. |
   
   - **Defaults:** every new option is optional. `operation` has a `default` 
only for EC2 and Secrets Manager, where the component has none and the template 
pinned the operation in the URI; the default is that same operation, so the URI 
does not change. For Lambda the component defaults to `invokeFunction`, so the 
option has no `default` and drops out of the URI when unset. With all the new 
options unset, the endpoint URIs are byte-identical to `main`'s (see below).
   - **Lambda operations:** only those that need nothing but the function name, 
which the template already binds. The operations that need more input (create 
or update a function, aliases, permissions, event source mappings, tags) and 
`deleteFunction` are left out.
   - **EC2 operations:** only those whose only input is the instance IDs, which 
the template already takes from `instanceIds` / `ce-instanceids`. The 
template's steps are unchanged; only its comment is updated for the new option. 
`createAndRunInstances`, `createTags` and `deleteTags` need input (image, 
instance type, tags) that the Kamelet has no options or headers for, and 
`terminateInstances` cannot be undone, so they are left out. Start, stop and 
reboot without the header fail with `Instances Ids must be specified`; they 
never act on all instances.
   - **Secrets Manager:** `createSecret` names the new secret as before: from 
the `secret-name` header, else `ce-secret-name`, else the message ID. 
`updateSecret` and `getSecret` work on the secret in the new `secretId` option 
(name or ARN, with a `pattern:`). The template now starts with a `choice` on 
the operation: `createSecret` runs the naming steps of `main`, unchanged; the 
other two set `CamelAwsSecretsManagerSecretId` from `secretId`, or, when it is 
not set, fail the message with `IllegalArgumentException: The secretId option 
must be set for the updateSecret operation` (or `getSecret`) before anything is 
sent to AWS. `CamelAwsSecretsManagerSecretVersionId` is declared as an output 
header of `getSecret`.
   - **Translate, behaviour change:** `sourceLanguage` is no longer `required`, 
since with `autodetectSourceLanguage` it is not used. Its mapping is now 
`{{?sourceLanguage}}`; when it is set, the URI is as before. With neither 
option, the Kamelet starts, and a message fails with `The source language is 
missing: ...` unless it carries the `CamelAwsTranslateSourceLanguage` header; 
on `main` the Kamelet did not start.
   - **Translate terminology:** the component has no endpoint option for it, 
only the `CamelAwsTranslateTerminologyNames` header, which it reads as a 
`Collection`. `${split(...)}` gives a `String[]`, which converts to one. The 
`choice` sets the header only when the option is set, so with the option unset 
the template does the same as on `main`.
   - **`pattern:`:** `terminologyNames` follows the name pattern of Amazon 
Translate (`^([A-Za-z0-9-]_?)+$`), and `lexiconNames` that of Polly 
(`[0-9A-Za-z]{1,20}`), both as comma-separated lists.
   - **Descriptions:** the "Good to know" paragraphs and the option 
descriptions say what each operation gives in the body. The partial pages have 
new sections with an example: "Reading the Settings of a Function or Publishing 
a Version", "Starting, Stopping and Rebooting Instances", "Changing or Reading 
a Secret", "Detecting the Language and Custom Terminologies" and "Pronunciation 
Lexicons".
   
   **Left out, as they need a change in Camel first:**
   - **Asynchronous Lambda invocation (`InvocationType=Event`):** 
camel-aws2-lambda has no option or header for the invocation type; it always 
calls the function synchronously. The only way is `pojoRequest` with an 
`InvokeRequest` body built in Java, which a Kamelet cannot do. The Lambda 
description says that each call waits until the function ends. A Camel change 
could add an `invocationType` option (and header).
   - **Paging of `aws-timestream-query-sink`:** the query operation of 
camel-aws2-timestream reads only `CamelAwsTimestreamQueryString` and 
`CamelAwsTimestreamQueryMaxRows`. It takes no next token and sets none, so the 
next page of a result cannot be asked for. Setting only the maximum number of 
rows does not give paging, so `aws-timestream-query-sink` is unchanged. A Camel 
change could add a next-token header in and out, or fetch all the pages.
   
   ### Verification
   
   Tested with Camel JBang 4.24.0-SNAPSHOT:
   - Lambda, EC2 and Secrets Manager: `floci/floci` (2.5.0). Floci runs the 
Lambda functions (a Python function that sleeps 5 seconds and echoes its event) 
and the EC2 instances as Docker containers.
   - `aws-lambda-sink`, `aws-secrets-manager-sink` and `aws-translate-action` 
have no endpoint override option, so they were pointed at the stand-in with the 
AWS SDK's `AWS_ENDPOINT_URL` environment variable.
   - Translate and Polly: Floci's Translate returns the text as it is and 
ignores terminologies, and Floci has no Polly. So a local recording HTTP server 
stood in for both. It decodes each request (Smithy RPC v2 CBOR for Translate, 
JSON for Polly), logs it, and answers like the service. The table shows what 
reached it.
   
   | Case | Result |
   |---|---|
   | All new options unset, the five Kamelets, `main` and this branch | `camel 
get endpoint --json` shows identical endpoint URIs |
   | Lambda, `operation` unset | The function is called: body `{"echo": 
{"orderId": "A-1"}, "slept": 5}` after 5 s, `CamelAwsLambdaStatusCode` 200 |
   | Lambda, `invokeFunction` | The same |
   | Lambda, `getFunction` | `GetFunctionResponse`: name `w6svc-echo`, runtime 
`python3.12`, code location |
   | Lambda, `getFunctionConfiguration` | `GetFunctionConfigurationResponse`: 
timeout 30, memory 128, handler `handler.handler` |
   | Lambda, `publishVersion`, with `CamelAwsLambdaVersionDescription: release 
one` | `PublishVersionResponse`: version `1`, description `release one` |
   | Lambda, `listVersions` after that | `ListVersionsByFunctionResponse` with 
2 versions (`$LATEST`, `1`) |
   | Lambda, `listAliases` | `ListAliasesResponse(Aliases=[])` |
   | Lambda, `listFunctions` | `ListFunctionsResponse` with 1 function, 
`w6svc-echo` |
   | EC2, `operation` unset, `instanceIds` = one instance | 
`DescribeInstanceStatusResponse` for that instance: `running`, checks `ok` |
   | EC2, `describeInstances` | `DescribeInstancesResponse`, instance type 
`t2.micro` |
   | EC2, `stopInstances` | `StopInstancesResponse` `running` -> `stopping`; 
Floci then reports `stopped` and its container exits |
   | EC2, `startInstances` on that stopped instance | `StartInstancesResponse` 
`stopped` -> `pending`; Floci then reports `running` and its container runs |
   | EC2, `rebootInstances` | Floci logs `Rebooted EC2 container`, and the 
container's start time changes; the body is left as it was |
   | EC2, `stopInstances` without `instanceIds` | Fails: `Instances Ids must be 
specified` |
   | EC2, `stopInstances` on Camel 4.23.0 | 
`StopInstancesResponse(StoppingInstances=[])`: no instance is stopped (the 
description says so) |
   | Secrets Manager, `operation` unset, `secret-name: w6svc/db-password`, body 
`first-value` | `CreateSecretResponse` |
   | `operation` unset, `ce-secret-name: w6svc/ce-named` | Created as 
`w6svc/ce-named` |
   | The same name again, `operation` unset | Fails: `ResourceExistsException`, 
as on `main` |
   | `updateSecret`, `secretId: w6svc/db-password`, body `second-value` | 
`UpdateSecretResponse` with a new version ID |
   | `getSecret`, `secretId: w6svc/db-password` | Body `second-value` (a 
`String`), `CamelAwsSecretsManagerSecretVersionId` = the new version ID |
   | `getSecret`, `secretId` = the ARN of that secret | Body `second-value` |
   | `updateSecret`, `secretId: w6svc/db-password`, message with `secret-name: 
w6svc/other` | `w6svc/db-password` gets the new value; `w6svc/other` keeps its 
value |
   | `updateSecret` without `secretId` | Fails: `IllegalArgumentException: The 
secretId option must be set for the updateSecret operation`; no secret changes |
   | `getSecret` without `secretId` | Fails: `IllegalArgumentException: The 
secretId option must be set for the getSecret operation` |
   | `getSecret`, `secretId` of a missing secret | Fails: 
`ResourceNotFoundException` |
   | `createSecret` with `secretId` set and no name header | Created under the 
message ID; `secretId` is not used |
   | `binaryPayload: true`, `createSecret`, body `binary-bytes` | The AWS CLI 
shows `SecretBinary` (`YmluYXJ5LWJ5dGVz`) and no `SecretString`; `getSecret` 
gives a `byte[]` |
   | `binaryPayload: true`, `updateSecret` with `secretId`, body `new-binary`, 
then `getSecret` | `byte[]` with `new-binary` |
   | Translate, options unset, `sourceLanguage: it` | Request: 
`SourceLanguageCode: it`, no `TerminologyNames` |
   | Translate, `autodetectSourceLanguage: true`, no `sourceLanguage` | 
Request: `SourceLanguageCode: auto` |
   | Translate, `autodetectSourceLanguage: true` and `sourceLanguage: de` | 
Request: `SourceLanguageCode: auto` |
   | Translate, neither | The Kamelet starts; the message fails: `The source 
language is missing: ...` |
   | Translate, `terminologyNames: product-names` | Request: `TerminologyNames: 
["product-names"]` |
   | Translate, `terminologyNames: product-names,brand_names` | Request: 
`TerminologyNames: ["product-names", "brand_names"]` |
   | Polly, `lexiconNames` unset | Request without `LexiconNames`; body is the 
audio, `CamelAwsPollyContentType` `audio/mpeg` |
   | Polly, `lexiconNames: w3c` | Request: `LexiconNames: ["w3c"]` |
   | Polly, `lexiconNames: w3c,acronyms` | Request: `LexiconNames: ["w3c", 
"acronyms"]` |
   
   `./mvnw clean verify -DskipTests` and then `./mvnw clean verify` passed from 
the root. Before building, the library copies of the five Kamelets were 
refreshed with `./mvnw -pl library/camel-kamelets 
resources:copy-resources@copy-resource-one`. The build regenerated 
`kamelets-index.json`. No option counts in `KameletsCatalogTest` needed 
changing.
   
   _Claude Code on behalf of Claus Ibsen_
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to