oracle / oci-java-sdk

Oracle Cloud Infrastructure SDK for Java
https://cloud.oracle.com/cloud-infrastructure
Other
192 stars 153 forks source link

Invoking function fails when SDK version updated from 3.9.1 to 3.13.0 and 3.14.0 #517

Open GindiKhangura opened 1 year ago

GindiKhangura commented 1 year ago

Invoking functions worked with SDK v3.9.1; after updating the version to 3.13.0 and 3.14.0, both versions throw the error com.oracle.bmc.model.BmcException: Error returned by InvokeFunction operation in FunctionsInvoke service.(404, NotAuthorizedOrNotFound, false) You're trying to invoke a function without setting the invoke endpoint.

Note: the same endpoint was provided in all cases (example: https://aabbcc112233.us-ashburn-1.functions.oci.oraclecloud.com).

I do not see any related breaking changes documented in the changelog.

KartikShrikantHegde commented 1 year ago

Hi @GindiKhangura , I doubt this has to do with SDK behavior because typically 404 error means either you don’t have the right permission to access the resource or the resource doesn’t exist. I would suggest checking if your permissions exist or got modified to point to a different resource/compartment etc, OR the resource exists in the correct location where you have the permission defined.

austinddavis commented 11 months ago

Updating this with some new information. I'm one of Gindi's teammates and I picked up the SDK update task and ended up figuring out what was happening. I've also provided a workaround for anyone else running into this issue at the end.

In 3.12.1 the BaseClient constructor was updated so that after the endpoint is set, the region is set which may override the endpoint already provided if a region is provided; In our case we provide the region, and the endpoint to the builder.

To confirm this was our issue I did a sanity check where we passed in the URL we received from the Function service, something similar to https://aabbcc112233.us-ashburn-1.functions.oci.oraclecloud.com, alongside the region, built a new FunctionsInvokeClient, then finally called client.getEndpoint(), the endpoint we provided was not returned, instead we were returned "https://functions.us-ashburn-1.oci.oraclecloud.com". This incorrect endpoint URL being set by the OCI SDK is what was causing our 404 issues.

-- Workaround --

Calling 'client.setEndpoint(String endpoint)` after constructing the client correctly sets the endpoint.