aws:executeScript – Run a script
Runs the Python or PowerShell script provided using the specified runtime and handler. (For PowerShell, the handler is not required.)
Currently, the aws:executeScript
action contains the following
preinstalled PowerShell Core modules.
-
Microsoft.PowerShell.Host
-
Microsoft.PowerShell.Management
-
Microsoft.PowerShell.Security
-
Microsoft.PowerShell.Utility
-
PackageManagement
-
PowerShellGet
To use PowerShell Core modules that are not preinstalled, your script must install
the
module with the -Force
flag, as shown in the following command.
Install-Module
ModuleName
-Force
To use PowerShell Core cmdlets in your script, we recommend using the
AWS.Tools
modules, as shown in the following commands.
Installing the AWSPowerShell.NetCore
module is not supported.
-
Amazon S3 cmdlets.
Install-Module AWS.Tools.S3 -Force Get-S3Bucket -BucketName
bucketname
-
Amazon EC2 cmdlets.
Install-Module AWS.Tools.EC2 -Force Get-EC2InstanceStatus -InstanceId
instanceId
-
Common, or service independent AWS Tools for Windows PowerShell cmdlets.
Install-Module AWS.Tools.Common -Force Get-AWSRegion
If your script initializes new objects in addition to using PowerShell Core cmdlets, you must also import the module as shown in the following command.
Install-Module AWS.Tools.EC2 -Force Import-Module AWS.Tools.EC2 $tag = New-Object Amazon.EC2.Model.Tag $tag.Key = "
myTag
" $tag.Value = "myTagValue
" New-EC2Tag -Resourcei-12345678
-Tag $tag
For examples of installing and importing AWS.Tools
modules, and using
PowerShell Core cmdlets in runbooks, see Walkthrough: Using Document
Builder to create a custom runbook.
Each aws:executeScript
action can run up to a maximum duration of 600
seconds (ten minutes). You can limit the timeout by specifying the
timeoutSeconds
parameter for an aws:executeScript
step.
Input
Provide the runtime and handler required to run the provided Python 3.6, Python 3.7, or PowerShell Core 6.0 script.
The script input parameter is not supported for JSON runbooks. JSON runbooks must provide script content using the attachment input parameter.
- Runtime
-
The runtime language to be used for executing the provided script. Currently, aws:executeScript supports Python 3.6 (python3.6), Python 3.7 (python3.7), and PowerShell Core 6.0 (dotnetcore2.1) scripts.
Supported values:
python3.6
|python3.7
|PowerShell Core 6.0
Type: String
Required: Yes
- Handler
-
The entry for running the script, usually a function name. You must ensure the function defined in the handler has two parameters,
events
andcontext
. (Not required for PowerShell.)Type: String
Required: Yes (Python) | No (PowerShell)
- InputPayload
-
A JSON or YAML object that will be passed to the first parameter of the handler. This can be used to pass input data to the script.
Type: String
Required: No
- Script
-
An embedded script that you want to run during the automation. (Not supported for JSON runbooks.)
Type: String
Required: No (Python) | Yes (PowerShell)
- Attachment
-
The name of a standalone script file or .zip file that can be invoked by the action. To invoke a file for Python, use the
filename.method_name
format inHandler
. For PowerShell, invoke the attachment using and inline script. Gzip is not supported.When including Python libraries in your attachment, we recommend adding an empty
__init__.py
file in each module directory. This enables you to import the modules from the library in your attachment within your script content. For example:from library import module
Type: String
Required: No
Output
- Payload
-
The JSON representation of the object returned by your function.