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개 답변
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
지원 엔지니어
답변함 2년 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠