2 Answers
- Newest
- Most votes
- Most comments
1
Hi
You can use f strings method for simple dynamic parameter insertion.
logpath = f"{instance_id}:{accountId}:{_time}.log"
print(logpath)
calmScanCmd = ssm_client.send_command(
InstanceIds=['i-0c7f20d36a7338a62'],
DocumentName='AWS-RunShellScript',
Parameters={'commands': [f"sh /tmp/executeScript.sh {logpath}"]},
Comment='calling clam scan script'
)
print(calmScanCmd)
Reference from StackFlow https://stackoverflow.com/questions/71893560/how-to-execute-aws-ssm-send-command-to-run-shell-script-with-arguments-from-lamb
0
Hi,
You have a full sample of working code in this gist: https://gist.github.com/arnathan2k/30c8fc5b3fda7e3e100877bdd1eef995
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
Best,
Didier
Relevant content
- asked 2 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated a year ago
Thanks for sharing .. :)