How to run user data in windows instance using boto3

0 votes


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


# Create the instance
instanceDict = ec2.create_instances(
    DryRun = dryRun,
    ImageId = "ami-xxxxx",
    KeyName = "ZabbixServerPrivateKey",
    InstanceType = "t2.micro",
    SecurityGroupIds = ["sg-xxxxxxx"],
    MinCount = 1,
    MaxCount = 1,
Oct 13, 2020 in AWS by Lakshminarayanan
• 1,370 points

edited Oct 13, 2020 by MD 2,955 views

1 answer to this question.

+1 vote


I think you used the wrong keyword in the create_instance method. You can pass  user_data as a key. But you have used UserData. So change the key and try once. If you need more information then check all the key that is supported by the create_instances method.

answered Oct 13, 2020 by MD
• 95,440 points
I just followed this link.

but they used for linux based Ec2 instance.

Any idea for windows based instance?

First, replace the line UserData=user_data with user_data=user_data. It supports only the user_data key.

when i use user_data instead of UserData

raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:
Unknown parameter in input: "user_data", must be one of: BlockDeviceMappings, ImageId, InstanceType, Ipv6AddressCount, Ipv6Addresses, KernelId, KeyName, MaxCount, MinCount, Monitoring, Placement, RamdiskId, SecurityGroupIds, SecurityGroups, SubnetId, UserData, AdditionalInfo, ClientToken, DisableApiTermination, DryRun, EbsOptimized, IamInstanceProfile, InstanceInitiatedShutdownBehavior, NetworkInterfaces, PrivateIpAddress, ElasticGpuSpecification, ElasticInferenceAccelerators, TagSpecifications, LaunchTemplate, InstanceMarketOptions, CreditSpecification, CpuOptions, CapacityReservationSpecification, HibernationOptions, LicenseSpecifications, MetadataOptions


You can go through the below official document. In the Boto3 you can use the UserData key. You will also get the idea of why you are getting the above error.

Hi ,

I got solution,,,its simple mistake. That boto3 script is good.

why user-data not applied? - Because password length is not allow me to run the simple user creation command. When i used simple password than complex (like 8 digit password than 22 digit password), then user-data is applied.

Many thanks for ur kind


I am glad you got the solution. Keep upvoting the answer if you feel it is helpful to you. Hope we can assist you in the long run.

Related Questions In AWS

0 votes
1 answer

How to Pass the VPC ID while creating the Ec2 instance in AWS using Python Boto3

import boto3 ec2 = boto3.resource('ec2') instance = ec2.create_instances( ...READ MORE

answered Jan 29, 2019 in AWS by Priyaj
• 58,090 points
0 votes
1 answer

In Amazon Data Pipeline, how to make sure only once instance of a pipeline is running at any time?

On the CopyTablesActivity, you could set a lateAfterTimeout attribute ...READ MORE

answered Sep 19, 2018 in AWS by Priyaj
• 58,090 points
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
+1 vote
1 answer

To create user credential in EC2 instance from remote using Boto3 or Python?

Hi@Lakshminarayanan, You can create a user from your ...READ MORE

answered Oct 7, 2020 in AWS by MD
• 95,440 points
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP