I have a Commandbox interceptor that uses the onCL...
# docker-commandbox
d
I have a Commandbox interceptor that uses the onCLIStart function to pull some secrets from AWS and store them in the environment. Previously this was done on an EC2 instance directly which has the appropriate instance role. Im trying to move the same code to a container, but during the build process, I install my interceptor (as a package which requires aws-cfml), I get an error during the build process because no aws credentials exist. More detail in thread...
Copy code
component {

    property name='aws' inject='aws@awscfml';
    property name='moduleSettings' inject='commandbox:moduleSettings:studylink-env';
    property name='systemSettings' inject='systemSettings';

    public void function onCLIStart( required struct interceptData ) {
        systemOutput(moduleSettings)
       // Pull the secrets from SecretManager and create environment variables for them
        var secret_response = aws.secretsmanager.GetSecretValue( SecretId=moduleSettings.secretId, region = moduleSettings.defaultRegion );
        var secrets = deserializejson(secret_response.data.SecretString)
        for (var secret in secrets) {
            systemSettings.setSystemSetting( secret, secrets[ secret ] );
        } 
    }
}
Copy code
11.62    | Eureka, '/app/studylink-env/' has been installed!
11.62    | Activating your new module for instant use...
11.62    | √ | Installing package [forgebox:aws-cfml@1.33.0]
11.64 
11.64 
11.64 
11.64 ERROR (5.9.1+00767)
11.64 
11.64 Error building: aws@awscfml -> Unable to resolve AWS credentials..
11.64 
11.64 DSL: , Path: /usr/local/lib/CommandBox/cfml/modules/studylink-env/modules/awscfml.aws,Error Location:/usr/local/lib/CommandBox/cfml/modules/studylink-env/modules/awscfml/com/credentials.cfc:97/usr/local/lib/CommandBox/cfml/modules/studylink-env/modules/awscfml/com/credentials.cfc:13/usr/local/lib/CommandBox/cfml/modules/studylink-env/modules/awscfml/com/api.cfc:17/usr/local/lib/CommandBox/cfml/modules/studylink-env/modules/awscfml/aws.cfc:63
11.64 /system/wirebox/system/ioc/Builder.cfc: line 220
11.64 218:                                      detail = "DSL: #thisMap.getDSL()#, Path: #thisMap.getPath()#,
11.64 219:                                      Error Location:
11.64 220:                                      #reducedTagContext#"
11.64 221:                              );
11.64 222:                      }
Why is aws-cfml trying to get credentials during the build process? I tried to not use the aws as a property property in the component, but I cant seem to figure out how to use the module in the onCliStart
b
I don't think your intereceptor is even firing
The error is when building the
aws@awscfml
instance which is injected into your class
Copy code
property name='aws' inject='aws@awscfml';
I didn't write that class, so I'm not sure what it does when it loads. But the validation happening is inside of there.
I'm not sure what you mean when you say "the build process", but are you installing a module that registers an interceptor that you don't actually want to fire??
d
Yep, its firing when I do
docker build
b
If that CFC basically refuses to load with no credentials, then you basically can't use it if there are no creds present, lol
I'd speak to the author of that lib to have it fail safe and just become a no-op or error on first use
instead of blowing up right away
CommandBox really has no control over this
If you register an interceptor, we will create it, and wire up its dependencies
d
I should be able to call the module from within onCliStart, without setting it as a property in the component?
like...
new module.aws...
I just cant figure out how to call it from the method in the interceptor
b
That's not it, but yes you can get a dependency at runtime. However, I don't think that solves your problem
If you are going to have the module active at a point when the CLI starts, it's going to use that 3rd part lib regardless
so it doesn't matter how or when you get it if you're still going to end up trying to use it
UNless you want ot put the loading of it behind a check for settings
That could work
d
thats ok, I can handle that with a try/catch in the interceptor
b
It's just
Copy code
getInstance( dsl="aws@awscfml" )
Nah, try/catch is nasty. Just skip the logic entirely if the settings are there
actually
getInstance( "aws@awscfml" )
should work too since that's not really a DSL
You MAY need to do
wirebox.getINstance()
. I'm not sure what you have access to right there
d
this is in the module config, or in the interceptor method?
b
wherever the heck you want the CFC, lol
you tell me
I would do it in the actual
onCLIStart()
if it were me
Inside an if that checks for whatever config the sdk is going to look for
d
ok, let me try that
that will do the trick, I thin it was that
getInstance
to load the included module I was missing.
Copy code
[INFO] 2024-03-13T22:01:25Z - Error building: aws@awscfml -> Unable to resolve AWS credentials.
                                        . √ | Starting Server
   |------------------------------
   | Looking for server JSON file by convention: /app//server.json
So it still errors with missing creds, but server can still start (which we need for local dev)
Cheers @bdw429s
👍 1