I'm struggling with putting a sed
command into a YAML AWS CloudFormation template, which is handled from a serverless template.
So, the command I need to execute inside my AWS::CloudFormation::Init
block is:
sed -i.bak '/PRE_CLASSPATH=/c\PRE_CLASSPATH="${MW_HOME}/bi/bifoundation/jdbc/jdk18/bijdbc.jar${CLASSPATHSEP}${WL_HOME}/modules/net.shibboleth.utilities.java-support.jar${CLASSPATHSEP}${WL_HOME}/modules/org.slf4j.slf4j-api.jar${CLASSPATHSEP}${PRE_CLASSPATH}"' /opt/oracle/config/domains/bi/bin/setDomainEnv.sh
First I had issues with ${Variables}
since Serverless thought they were variables it should concern about. I workarounded it using a !Join
function to break up the command in this way (this approach doesn't work on Serverless):
cmd03_01:
command: !Join
- ''
- - sed -i.bak '/PRE_CLASSPATH=
- '/c\PRE_CLASSPATH="'
- '$'
- '{MW_HOME}/bi/bifoundation/jdbc/jdk18/bijdbc.jar'
- '$'
- '{CLASSPATHSEP}'
- '$'
- '{WL_HOME}/modules/net.shibboleth.utilities.java-support.jar'
- '$'
- '{CLASSPATHSEP}'
- '$'
- '{WL_HOME}/modules/org.slf4j.slf4j-api.jar'
- '$'
- '{CLASSPATHSEP}'
- '$'
- '{PRE_CLASSPATH}"'
- ' /opt/oracle/config/domains/bi/bin/setDomainEnv.sh'
This doesn't produce the desired output since someone (Serverless or CloudFormation or YAML interpreter) is scaping the backslash and the double-quotes.
My result is something like:
sed -i.bak '/PRE_CLASSPATH=/c\\PRE_CLASSPATH=\"${MW_HOME}/bi/bifoundation/jdbc/jdk18/bijdbc.jar${CLASSPATHSEP}${WL_HOME}/modules/net.shibboleth.utilities.java-support.jar${CLASSPATHSEP}${WL_HOME}/modules/org.slf4j.slf4j-api.jar${CLASSPATHSEP}${PRE_CLASSPATH}\" /opt/oracle/config/domains/bi/bin/setDomainEnv.sh
As you can see, is adding an extra '' on the current '' character and on the double-quotes.
I tried to escape the string on my YAML to avoid this behavior, but it was worst.
Any ideas or suggestions to have my literal command on the YAML template?
Thanks