Last active
October 6, 2022 01:56
-
-
Save arnathan2k/30c8fc5b3fda7e3e100877bdd1eef995 to your computer and use it in GitHub Desktop.
Lambda SSM Send Command Boto3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from __future__ import print_function | |
import json | |
import boto3 | |
import urllib.request | |
print('Loading function') | |
def lambda_handler(event, context): | |
try: | |
ec2_client = boto3.client('ec2', region_name='us-west-1') | |
print(contents) | |
running_instances = [instance.get('InstanceId') for instance in ec2_client.describe_instance_status().get('InstanceStatuses') if instance.get('InstanceState').get('Code')==16] | |
ssm_client = boto3.client('ssm', region_name='us-west-1') | |
params={"commands":["mkdir:\winevt","robocopy c:\Windows\System32\winevt\logs c:\winevt","Compress-Archive c:\winevtcompress"],"workingDirectory":["c:\"],"executionTimeout":["3600"]} | |
print(running_instances[0]) | |
response = ssm_client.send_command(DocumentName="AWS-RunPowerShellScript", InstanceIds=running_instances,Comment='logging the', TimeoutSeconds=600, Parameters=params) | |
except Exception as e: | |
raise e | |
else: | |
print('------------- succeded ---------------------') | |
finally: | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment