Hi,
I would like to launch windows ec2 instance using boto3. But I need to run some user data too. Is possible to place user-data during the launch ec2 instance? I have tried with the below code. But not creating anything.
#!/usr/bin/env python3
import boto3
import time
dryRun = False; # useful variable to put the script into dry run mode where the function allows it
ec2Client = boto3.client('ec2')
ec2Resource = boto3.resource('ec2',region_name='us-west-2')
ec2 = boto3.resource('ec2')
user_data = '''<script>
net user /add Latchu ABC@123
net localgroup administrators Latchu /add
</script>'''
# Create the instance
instanceDict = ec2.create_instances(
DryRun = dryRun,
ImageId = "ami-xxxxx",
KeyName = "ZabbixServerPrivateKey",
InstanceType = "t2.micro",
SecurityGroupIds = ["sg-xxxxxxx"],
MinCount = 1,
MaxCount = 1,
UserData=user_data
)