getlift / lift

Expanding Serverless Framework beyond functions using the AWS CDK
MIT License
920 stars 112 forks source link

"Constructs are not initialized" when using SQS Queue with `--aws-profile` serverless argument #351

Closed hschimpf closed 1 year ago

hschimpf commented 1 year ago

Description

When using a different AWS profile through serverless --aws-profile <profile>, for some reason this validation is caught when running the deploy process.

It only happens when I try to use a different AWS profile, if I don't specify the parameter --aws-profile the deploy process works as intended.

How to Reproduce

It only happens when the environment variable SQS_QUEUE is present, and using ${construct:jobs.queueUrl} as value

serverless.yml

provider:
    # ...
    environment:
        # ...
        QUEUE_CONNECTION: sqs
+       SQS_QUEUE: ${construct:jobs.queueUrl}

functions:
    # ...

constructs:
    jobs:
        type: queue
        worker:
            handler: Bref\LaravelBridge\Queue\QueueHandler
            runtime: php-81
            timeout: 60 # seconds

Additional Information

mnapoli commented 1 year ago

Could you share the exact command and CLI output? serverless --aws-profile <profile-name> is not a deployment, so maybe that's why?

hschimpf commented 1 year ago

Sorry, the command used is serverless --aws-profile <profile> deploy (I've updated the original text).

Here is the output (Ran on a fresh laravel proyect):

hschimpf@hschimpf:~/Temporal/laravel-9.x/ 28 files, 900K
ā””ā”€ [Aug 08 09:00:34] ā”€>>  serverless --aws-profile ecommerce deploy
Running "serverless" from node_modules

Onboarding "laravel" to the Serverless Dashboard

? What org do you want to add this service to? [Skip]

? Do you want to deploy now? Yes

Deploying laravel to stage dev (us-east-1)
Environment: linux, node 16.20.1, framework 3.34.0 (local) 3.34.0v (global), plugin 6.2.3, SDK 4.3.2
Credentials: Local, "ecommerce" profile
Docs:        docs.serverless.com
Support:     forum.serverless.com
Bugs:        github.com/serverless/serverless/issues

Error:
Error: Resolution error: Constructs are not initialized: this should not happen.
Object creation stack:
  at Execute again with CDK_DEBUG=true to capture stack traces
    at _LiftPlugin.getConstructs (/home/hschimpf/Temporal/laravel-9.x/node_modules/serverless-lift/dist/src/plugin.js:218:13)
    at Object.produce (/home/hschimpf/Temporal/laravel-9.x/node_modules/serverless-lift/dist/src/plugin.js:247:35)
    at LazyAny.resolve (/home/hschimpf/Temporal/laravel-9.x/node_modules/aws-cdk-lib/core/lib/lazy.js:1:3897)
    at LazyAny.resolve (/home/hschimpf/Temporal/laravel-9.x/node_modules/aws-cdk-lib/core/lib/lazy.js:1:4487)
    at DefaultTokenResolver.resolveToken (/home/hschimpf/Temporal/laravel-9.x/node_modules/aws-cdk-lib/core/lib/resolvable.js:1:1238)
    at resolve (/home/hschimpf/Temporal/laravel-9.x/node_modules/aws-cdk-lib/core/lib/private/resolve.js:1:2510)
    at Object.resolve [as mapToken] (/home/hschimpf/Temporal/laravel-9.x/node_modules/aws-cdk-lib/core/lib/private/resolve.js:1:892)
    at TokenizedStringFragments.mapTokens (/home/hschimpf/Temporal/laravel-9.x/node_modules/aws-cdk-lib/core/lib/string-fragments.js:1:1365)
    at DefaultTokenResolver.resolveString (/home/hschimpf/Temporal/laravel-9.x/node_modules/aws-cdk-lib/core/lib/resolvable.js:4:358)
    at resolve (/home/hschimpf/Temporal/laravel-9.x/node_modules/aws-cdk-lib/core/lib/private/resolve.js:1:1816)
    at Object.resolve (/home/hschimpf/Temporal/laravel-9.x/node_modules/aws-cdk-lib/core/lib/private/resolve.js:1:892)
    at resolve (/home/hschimpf/Temporal/laravel-9.x/node_modules/aws-cdk-lib/core/lib/private/resolve.js:1:2787)
    at Object.resolve (/home/hschimpf/Temporal/laravel-9.x/node_modules/aws-cdk-lib/core/lib/private/resolve.js:1:892)
    at resolve (/home/hschimpf/Temporal/laravel-9.x/node_modules/aws-cdk-lib/core/lib/private/resolve.js:1:2787)
    at Function.resolve (/home/hschimpf/Temporal/laravel-9.x/node_modules/aws-cdk-lib/core/lib/token.js:1:3770)
    at resolveTokens (/home/hschimpf/Temporal/laravel-9.x/node_modules/serverless-lift/dist/src/plugin.js:368:46)
    at _LiftPlugin.resolveLazyVariables (/home/hschimpf/Temporal/laravel-9.x/node_modules/serverless-lift/dist/src/plugin.js:373:40)
    at initialize (/home/hschimpf/Temporal/laravel-9.x/node_modules/serverless-lift/dist/src/plugin.js:103:14)
    at PluginManager.run (/home/hschimpf/Temporal/laravel-9.x/node_modules/serverless/lib/classes/plugin-manager.js:598:65)
    at async Serverless.run (/home/hschimpf/Temporal/laravel-9.x/node_modules/serverless/lib/serverless.js:179:5)
    at async Object.run (/home/hschimpf/Temporal/laravel-9.x/node_modules/serverless/lib/cli/interactive-setup/deploy.js:91:5)
    at async module.exports (/home/hschimpf/Temporal/laravel-9.x/node_modules/serverless/lib/cli/interactive-setup/index.js:106:7)
    at async /home/hschimpf/Temporal/laravel-9.x/node_modules/serverless/scripts/serverless.js:804:36
mnapoli commented 1 year ago

The correct command is serverless deploy --aws-profile <profile>

Unfortunately in Node they don't have the great Symfony Console component šŸ˜‚, their CLI parsers cannot understand <options> <command>, you have to use <command> <options>.

hschimpf commented 1 year ago

Oh boy... I feel dumb šŸ¤£

It works, thank you.