Best Python code snippet using localstack_python
AWS_EC2_Automate_Script.py
Source:AWS_EC2_Automate_Script.py
...72# In[24]:73# A low-level Client representing AWS Identity and Access Management74client = boto3.client('iam')75# Uploads an SSH Public Key and associates it with a user176response_client_1 = client.upload_ssh_public_key(77 UserName=data["server"]["users"][0]["login"],78 SSHPublicKeyBody=data["server"]["users"][0]["ssh_key"]79)80# In[ ]:81# Uploads an SSH Public Key and associates it with a user282response_client_2 = client.upload_ssh_public_key(83 UserName=data["server"]["users"][1]["login"],84 SSHPublicKeyBody=data["server"]["users"][1]["ssh_key"]85)86# In[17]:87# A low-level client representing AWS EC2 Instance Connect 88ec2_client = boto3.client('ec2-instance-connect')89# In[20]:90# Pushes an SSH public key to the specificied EC2 instance for the use by User1 91response_of_user1 = ec2_client.send_ssh_public_key(92 InstanceId= instance[0].id,93 InstanceOSUser= data["server"]["users"][0]["login"],94 SSHPublicKey= data["server"]["users"][0]["ssh_key"],95 AvailabilityZone= 'us-east-1a'96)...
iam.py
Source:iam.py
...12 UserName=values.user,13 PolicyArn='arn:aws:iam::aws:policy/IAMUserSSHKeys'14 )15 key = RSA.generate(2048)16 res = iam.upload_ssh_public_key(17 UserName=values.user,18 SSHPublicKeyBody=key.publickey().exportKey('OpenSSH')19 )20 ssh_id = res['SSHPublicKey']['SSHPublicKeyId']21 s3 = boto3.client('s3')22 s3.put_object(23 Bucket=values.bucket,24 Key=values.user,25 Metadata={26 'sshId': ssh_id27 },28 ACL='private',29 Body=key.exportKey('PEM')30 )
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!