javaoracle-cloud-infrastructure

Oracle OCI Function - Config file not accessible


Hello stackoverflow people!

I’m deploying a java function with Oracle cloud Shell.

I made all necessary configurations :

After that I deployed my Java function on a docker container with the command.

fn deploy —-app <app name>

Then I called my function:

fn invoke <app name> <function name>

The goal of my function is to update my Load Balancer RuleSet.

Finally I had an error message :

Error 502 : FunctionInvokeExecutionError 

Not a lot of traces available, but I identified that the following code was on error.

  final ConfigFileReader.ConfigFile configFile = 
                    ConfigFileReader.parse(“~/.oci/config“, “DEFAULT“);

The folder and the config file are not accessible by the function.

I tried to replace the config file by a new one generated with the command line

oci setup config 

I tried to test the function in local (with the config file in local as well) => it works.

Thank you very much for your help!


Solution

  • If you intend to interact with OCI resources from the function execution environment, you should consider using Resource Principal authorization as you are not including ~/.oci/config in the container.

    https://blogs.oracle.com/developers/post/instance-and-resource-principal-authentication-with-the-oci-typescriptjavascript-sdk

    Note that you need to create a dynamic policy and a policy to allow the function to manage the LoadBalancers in tenancy/compartment: https://redthunder.blog/2020/09/21/secure-inter-service-communication-in-oci/

    Here is an example using Resource Principal in Java: https://github.com/oracle/oci-java-sdk/blob/master/bmc-examples/src/main/java/FunctionsEphemeralResourcePrincipalAuthenticationDetailsProviderExample.java