How to call long-running User Data Script with parameters from Cloud Formation?

0

I have a PowerShell script, that when runs, installs a large application and start a server. This process takes about 20 minutes to run.

I would like to start this install process when the server is first created to avoid having to RDP into the server, and start the script manually.

The problem I'm having is that there is no sign of the user data script running in the server. There are no logs in C:\Program Files\Amazon.

The cloudformation script looks like this:

"UserData": { "Fn::Base64": { "Fn::Join": ["", [
                    "<powershell>\n",
                    "Set-Location C:\\Users\\Administrator\\Documents\\installer-and-scripts\\ \n",
                    ".\\AddNewAppServer.ps1 ", { "Ref" : "RDSEndpoint" }, " ", { "Ref" : "DBAdminUser" }, " ", { "Ref" : "DBAdminPassword" }, " ", { "Ref" : "S3BackupFileARN" }, " ", { "Ref" : "NewdbName" }, " \n", 
                    "</powershell>"]]
                  }}

The five variables in UserData are parameters of the Cloudformation script and are just Strings.

Why do I not see any sign of this script running? Also, will having a 20-minute script cause issues in logging into the server or even run at all?

Thanks!

1 Answer
0

UserData scripts indeed allow you to perform automated configuration tasks or to run scripts after the instance starts. To troubleshoot missing execution of user data scripts on an EC2 Windows instance, you could reference this knowledge article.

In order to further confirm any challenges from the script itself, could you please also try using the same in a test instance with static values (outside of CloudFormation). Having said that, AWS CloudFormation by default does not have a timeout for stack creation.

AWS
SUPPORT ENGINEER
answered 2 years 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