I have requirement to wait for file to be present before executing next steps

0

Hi Team

I have a simple use case we have an organization provided soe and want to do customisation on top of that. Its a windows machine, so org specific bootstrap does some restart and once it completes , a file gets created in C: drive.

I need to make sure that my customization runs after the organisation specific bootstrap is completed.

I have this in userdata UserData: Fn::Base64: !Sub | <powershell> cfn-init.exe -v --stack ${AWS::StackName} --resource CPMLaunchTemplate --configsets full-install --region ${AWS::Region} <powershell>

and myconfigset looks like this Metadata: AWS::CloudFormation::Init: configSets: full-install: - waitForBootstrap - configureWindowsDrive

    waitForBootstrap:
        1-deploy-wait-for-bootstrap:
          command: powershell.exe -command "while(-Not (Test-Path C:\bootstrap-complete.txt)) { Write-Host 'Waiting for file to be present';  Start-Sleep -Seconds 5 }"

     configureWindowsDrive:    
      commands:
        downloadDriveMappingFile:
          command: !Sub

.. .

Somehow my script isnt waiting forfile to be present an dmoving to next step of ConfigureWindowsDrive.

Not sue what i am doing wrong an how can i get that fixed.

varsha
asked a month ago403 views
1 Answer
0

Hello,

The provided PowerShell command works locally on a Windows machine, however the following needs to be remembered:

"Because paths on Windows use a backslash ('\') character, you must always remember to properly escape all backslashes by prepending another backslash whenever you refer to a Windows path in the AWS CloudFormation template." [1]

You will need to update your waitForBootstrap as follows:

    waitForBootstrap:
        1-deploy-wait-for-bootstrap:
          command: powershell.exe -command "while(-Not (Test-Path C:\\bootstrap-complete.txt)) { Write-Host 'Waiting for file to be present';  Start-Sleep -Seconds 5 }"

[1] https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/cfn-windows-stacks-bootstrapping.html

Duane
answered a month ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions