aws:executeScript - 스크립트 실행 - AWS Systems Manager

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

aws:executeScript - 스크립트 실행

지정된 런타임 및 핸들러를 사용하여 제공된 Python 또는 PowerShell 스크립트를 실행합니다. 각 aws:executeScript 작업은 최대 600초(10분)까지 실행할 수 있습니다. aws:executeScript 단계에서 timeoutSeconds 파라미터를 지정하여 시간 제한을 제한할 수 있습니다.

함수에서 return 문을 사용하여 출력 페이로드에 출력을 추가합니다. aws:executeScript 작업에 대한 출력 정의 예시는 예제 2: 스크립팅된 실행서의 내용을 참조하세요. 실행서에 있는 aws:executeScript 작업의 출력을 지정하는 Amazon CloudWatch Logs 로그 그룹으로 전송할 수 있습니다. 자세한 내용은 CloudWatch Logs로 Automation 작업 출력 로깅 섹션을 참조하세요.

aws:executeScript 작업에서 CloudWatch Logs로 출력을 전송하거나 aws:executeScript 작업에 대해 지정한 스크립트가 AWS API 작업을 호출하는 경우, 런북을 실행하려면 AWS Identity and Access Management(IAM) 서비스 역할(또는 역할 수임)이 항상 필요합니다.

aws:executeScript 작업에는 다음과 같은 사전 설치된 PowerShell Core 모듈이 포함되어 있습니다.

  • Microsoft.PowerShell.Host

  • Microsoft.PowerShell.Management

  • Microsoft.PowerShell.Security

  • Microsoft.PowerShell.Utility

  • PackageManagement

  • PowerShellGet

사전 설치되지 않은 PowerShell Core 모듈을 사용하려면 스크립트에서 다음 명령과 같이 -Force 플래그를 사용하여 모듈을 설치해야 합니다. AWSPowerShell.NetCore 모듈은 지원되지 않습니다. ModuleName을 설치하려는 모듈로 바꿉니다.

Install-Module ModuleName -Force

스크립트에서 PowerShell Core cmdlet을 사용하려면 다음 명령과 같이 AWS.Tools 모듈을 사용하는 것이 좋습니다. 각 example resource placeholder를 사용자의 정보로 바꿉니다.

  • Amazon S3 cmdlet입니다.

    Install-Module AWS.Tools.S3 -Force Get-S3Bucket -BucketName bucketname
  • Amazon EC2 cmdlet.

    Install-Module AWS.Tools.EC2 -Force Get-EC2InstanceStatus -InstanceId instanceId
  • 공통 또는 서비스 독립적 AWS Tools for Windows PowerShell cmdlet입니다.

    Install-Module AWS.Tools.Common -Force Get-AWSRegion

스크립트에서 PowerShell Core cmdlet을 사용하는 것 외에 새 객체를 초기화하는 경우 다음 명령과 같이 모듈도 가져와야 합니다.

Install-Module AWS.Tools.EC2 -Force Import-Module AWS.Tools.EC2 $tag = New-Object Amazon.EC2.Model.Tag $tag.Key = "Tag" $tag.Value = "TagValue" New-EC2Tag -Resource i-02573cafcfEXAMPLE -Tag $tag

AWS.Tools 모듈 설치와 가져오기 및 실행서의 PowerShell Core cmdlet 사용 예는 문서 빌더를 사용하여 런북 생성 섹션을 참조하세요.

입력

스크립트를 실행하는 데 필요한 정보를 입력합니다. 각 example resource placeholder를 사용자의 정보로 바꿉니다.

참고

Python 스크립트의 첨부 파일은 스크립트가 포함된 .py 파일 또는 .zip 파일일 수 있습니다. PowerShell 스크립트는.zip 파일에 저장해야 합니다.

YAML
action: "aws:executeScript" inputs: Runtime: runtime Handler: "functionName" InputPayload: scriptInput: '{{parameterValue}}' Script: |- def functionName(events, context): ... Attachment: "scriptAttachment.zip"
JSON
{ "action": "aws:executeScript", "inputs": { "Runtime": "runtime", "Handler": "functionName", "InputPayload": { "scriptInput": "{{parameterValue}}" }, "Attachment": "scriptAttachment.zip" } }
런타임

제공된 스크립트를 실행하는 데 사용되는 런타임 언어입니다. aws:executeScript에서는 Python 3.7(python3.7), Python 3.8(python3.8), PowerShell Core 6.0(dotnetcore2.1) 및 PowerShell 7.0(dotnetcore3.1) 스크립트가 지원됩니다.

지원되는 값: python3.7 | python3.8 | PowerShell Core 6.0 | PowerShell 7.0

유형: 문자열

필수 항목 여부: 예

핸들러

함수의 이름입니다. 핸들러에 정의된 함수에 두 개의 파라미터 eventscontext가 있는지 확인해야 합니다. PowerShell 런타임은 이 파라미터를 지원하지 않습니다.

유형: 문자열

필수: 예(Python) | 지원되지 않음(PowerShell)

InputPayload

핸들러의 첫 번째 파라미터로 전달되는 JSON 또는 YAML 객체입니다. 이 스크립트에 입력 데이터를 전달하는 데 사용할 수 있습니다.

유형: 문자열

필수 항목 여부: 아니요

Python
description: Tag an instance schemaVersion: '0.3' assumeRole: '{{AutomationAssumeRole}}' parameters: AutomationAssumeRole: type: String description: '(Required) The Amazon Resource Name (ARN) of the IAM role that allows Automation to perform the actions on your behalf. If no role is specified, Systems Manager Automation uses your IAM permissions to operate this runbook.' InstanceId: type: String description: (Required) The ID of the EC2 instance you want to tag. mainSteps: - name: tagInstance action: 'aws:executeScript' inputs: Runtime: "python3.8" Handler: tagInstance InputPayload: instanceId: '{{InstanceId}}' Script: |- def tagInstance(events,context): import boto3 #Initialize client ec2 = boto3.client('ec2') instanceId = events['instanceId'] tag = { "Key": "Env", "Value": "Example" } ec2.create_tags( Resources=[instanceId], Tags=[tag] )
PowerShell
description: Tag an instance schemaVersion: '0.3' assumeRole: '{{AutomationAssumeRole}}' parameters: AutomationAssumeRole: type: String description: '(Required) The Amazon Resource Name (ARN) of the IAM role that allows Automation to perform the actions on your behalf. If no role is specified, Systems Manager Automation uses your IAM permissions to operate this runbook.' InstanceId: type: String description: (Required) The ID of the EC2 instance you want to tag. mainSteps: - name: tagInstance action: 'aws:executeScript' inputs: Runtime: PowerShell 7.0 InputPayload: instanceId: '{{InstanceId}}' Script: |- Install-Module AWS.Tools.EC2 -Force Import-Module AWS.Tools.EC2 $input = $env:InputPayload | ConvertFrom-Json $tag = New-Object Amazon.EC2.Model.Tag $tag.Key = "Env" $tag.Value = "Example" New-EC2Tag -Resource $input.instanceId -Tag $tag
Script

자동화 중 실행할 기본 제공 스크립트입니다.

유형: 문자열

필수: 아니오(Python) | 예(PowerShell)

연결

작업에서 호출될 수 있는 독립형 스크립트 파일 또는.zip 파일의 이름입니다. Attachments 요청 파라미터에서 지정한 문서 첨부 파일의 Name과 동일한 값을 지정합니다. 자세한 내용은 AWS Systems Manager API 참조첨부 파일을 참조하세요. 첨부 파일을 사용하여 스크립트를 제공하는 경우 런북의 최상위 수준 요소에서 files 섹션 또한 정의해야 합니다. 자세한 내용은 스키마 버전 0.3 섹션을 참조하세요.

Python용 파일을 호출하려면 Handler에서 filename.method_name 형식을 사용합니다.

참고

Python 스크립트의 첨부 파일은 스크립트가 포함된 .py 파일 또는 .zip 파일일 수 있습니다. PowerShell 스크립트는.zip 파일에 저장해야 합니다.

첨부 파일에 Python 라이브러리를 포함할 때 각 모듈 디렉터리에 빈 __init__.py 파일을 추가하는 것이 좋습니다. 이를 통해 스크립트 내용 내 첨부 파일의 라이브러리에서 모듈을 가져올 수 있습니다. 예: from library import module

유형: 문자열

필수 항목 여부: 아니요

출력
Payload

함수에서 반환된 객체의 JSON 표현입니다. 최대 100KB가 반환됩니다. 목록을 출력하는 경우 최대 100개의 항목이 반환됩니다.