Issue between SSMRunCommand and EC2 in AWS

75 views Asked by At

I am a beginner in programming and also trying to get started with AWS. I want to use the Windows version of EC2 to connect to my home printer. But there seems to be an issue between the connection between SSMRunCommand and EC2. The code is as follows:

import json
import boto3

def lambda_handler(event, context):
    ssm_client = boto3.client('ssm',region_name='my-region')
    response = ssm_clinet.send_command(
        DocumentName='AWS-RunPowerShellScript',
        InstanceIds=['i-myIds'],
        Parameters={
                'commands':[
                    'Start-Process -FilePath "Z:/intest.pdf" -Verb Print | Out-Printer -Name "My Printer"',
                    '$text_path = "D:/Print.txt"', '$today=Get-Date','Write-Output $today | Out-File $text_path -Append]
                    }
            )
    command_id = response['Command']['CommandId']

    return{
        'statusCode':200,
        'body':json.dumps('Hello form Lambda')
    }

I gave lambda SSMFullAccess and EC2FullAccess. Connected to the printer using an IP address in EC2 and downloaded the printer SMM agent and Adobe PDF reader have also been installed in EC2. During testing, it was found that the "start process" command was not executed, but the "Write Out" command was executed. There were no errors, and the command status can be seen as successful in AWS System Manager. But there was no printing operation performed. When using Powershell with the same command inside EC2, a printing operation was executed. I'm not sure why.

0

There are 0 answers