Closed aquach closed 9 years ago
I found this pattern very useful for getting arbitrary parameters into files. For example, I have a cfn-init.sh script:
cfn-init.sh
#!/bin/bash -xe exec > >(tee -a /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1 echo BEGIN apt-get install -y python-pip python-dev build-essential pip install https://s3.amazonaws.com/cloudformation-examples/aws-cfn-bootstrap-latest.tar.gz cfn-init -v \ --stack {{ ref('AWS::StackName') }} \ --resource {{ locals[:resource_id] }} \ --region {{ ref('AWS::Region') }} cfn-signal -e $? \ --stack {{ ref('AWS::StackName') }} \ --resource {{ locals[:resource_id] }} \ --region {{ ref('AWS::Region') }} echo END
which requires the resource name. With this change, I can now do this:
interpolate(file('bootstrap-configs/cfn-init.sh'), { resource_id: 'MyInstance' })
The only way I could do this before was inlining the script into a heredoc in the ruby code, which is definitely less than ideal.
Sweet! I'm going to test this now; it will definitely streamline some of our messier stuff, if it works.
I found this pattern very useful for getting arbitrary parameters into files. For example, I have a
cfn-init.sh
script:which requires the resource name. With this change, I can now do this:
The only way I could do this before was inlining the script into a heredoc in the ruby code, which is definitely less than ideal.