Home > other >  expected <block end>, but found '<scalar>' in 'reader' in .ebextensi
expected <block end>, but found '<scalar>' in 'reader' in .ebextensi

Time:01-26

My command in .ebextensions is failing with the following error:

The configuration file .ebextensions/setvars.config in application version code-pipeline-1674590101261-00ce5911c1ae7ca5d24c81474ba76352008bc540 contains invalid YAML or JSON. YAML exception: Invalid Yaml: while parsing a block mapping in 'reader', line 3, column 5: command: "/opt/elasticbeanstalk/ ... ^ expected <block end>, but found '<scalar>' in 'reader', line 3, column 93: ... nt | jq -r 'to_entries | .[] | "export \(.key)=\"\(.value)\""' > ... ^ , JSON exception: Invalid JSON: Unexpected character (c) at position 0.. Update the configuration file.

The .ebextensions/setvars.config contains:

commands:
  setvars:
    command: "/opt/elasticbeanstalk/bin/get-config environment | jq -r 'to_entries | .[] | "export \(.key)=\"\(.value)\""' >> ~/.bash_profile"
packages:
  yum:
    jq: []

The snippet itself has been copied from was docs. Can someone please help me fixing this issue?

I want to run the command inside the double quotes in the elastic beanstalk when the application is starting.

EDIT: I added a backslash before the first quote which was making the YAML valid but then I got this error in cfn-init.log

2023-01-24 20:45:59,593 [ERROR] Command setvars (/"/opt/elasticbeanstalk/bin/get-config environment | jq -r 'to_entries | .[] | "export \(.key)=\"\(.value)\""' >> ~/.bash_profile") failed
2023-01-24 20:45:59,593 [ERROR] Error encountered during build of prebuild_0_checked_backend: Command setvars failed
Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 579, in run_config
    CloudFormationCarpenter(config, self._auth_config, self.strict_mode).build(worklog)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 278, in build
    self._config.commands)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/command_tool.py", line 127, in apply
    raise ToolError(u"Command %s failed" % name)
cfnbootstrap.construction_errors.ToolError: Command setvars failed
2023-01-24 20:45:59,596 [ERROR] -----------------------BUILD FAILED!------------------------
2023-01-24 20:45:59,596 [ERROR] Unhandled exception during build: Command setvars failed
Traceback (most recent call last):
  File "/opt/aws/bin/cfn-init", line 181, in <module>
    worklog.build(metadata, configSets, strict_mode)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 137, in build
    Contractor(metadata, strict_mode).build(configSets, self)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 567, in build
    self.run_config(config, worklog)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 579, in run_config
    CloudFormationCarpenter(config, self._auth_config, self.strict_mode).build(worklog)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/construction.py", line 278, in build
    self._config.commands)
  File "/usr/lib/python3.7/site-packages/cfnbootstrap/command_tool.py", line 127, in apply
    raise ToolError(u"Command %s failed" % name)
cfnbootstrap.construction_errors.ToolError: Command setvars failed

CodePudding user response:

You do not need quotations at the beginning and the end:

commands:
  setvars:
    command: /opt/elasticbeanstalk/bin/get-config environment | jq -r 'to_entries | .[] | "export \(.key)=\"\(.value)\""' >> ~/.bash_profile
packages:
  yum:
    jq: []
  • Related