Skip to content

Running powershell script already placed in EC2 #67

@macdrorepo

Description

@macdrorepo

Hello,

Not directly an issue but question on how to properly code that step as in subject. Currently have:

    execute_powershell = ssm_docs.RunPowerShellScriptStep(
        self,
        "execute_delicense_script",
        name="Run delicense script",
        run_command=[
            "C:\\cfn\\deactivate_license.ps1"
            ],
        exit_on_failure=True,
    )

but that's failing with:

RuntimeError: Passed to parameter props of new @cdklabs/cdk-ssm-documents.RunPowerShellScriptStep: Unable to deserialize value as @cdklabs/cdk-ssm-documents.RunPowerShellScriptStepProps
├── 🛑 Failing value is an object
│ { '$jsii.struct': [Object] }
╰── 🔍 Failure reason(s):
╰─ Key 'runCommand': Unable to deserialize value as array<@cdklabs/cdk-ssm-documents.IStringVariable>
├── 🛑 Failing value is an array
│ [ 'C:\cfn\deactivate_license.ps1' ]
╰── 🔍 Failure reason(s):
╰─ Index 0: Unable to deserialize value as @cdklabs/cdk-ssm-documents.IStringVariable
├── 🛑 Failing value is a string
│ 'C:\cfn\deactivate_license.ps1'
╰── 🔍 Failure reason(s):
╰─ Value does not have the "$jsii.byref" key

Also did try with this:

    execute_powershell = ssm_docs.RunPowerShellScriptStep(
        self,
        "execute_delicense_script",
        name="Run delicense script",
        run_command=[ssm_docs.StringVariable(reference="C:\\cfn\\deactivate_license.ps1")],
        exit_on_failure=True,
    )

but that's failing during deployment:
Resource handler returned message: "Invalid request provided: StepName: Run delicense script is invalid. at Line: 24, Column: 1

Whole script is:

    automation_document = ssm_docs.AutomationDocument(
        self,
        "delicense_adobe_servers",
        document_format=ssm_docs.DocumentFormat.YAML,
        document_name=f"{asg_name}-runbook",
        description="Delicense Adobe renderer servers",
        update_method="NewVersion",
        doc_inputs=[
            ssm_docs.Input.of_type_string(
                "ASGName", default_value=asg_name, description="(Required) Name of autoscaling group"
            ),
            ssm_docs.Input.of_type_string(
                "AutomationAssumeRole",
                description="(Required) The ARN of the role that allows automation to perform the actions on your behalf.",
            ),
            ssm_docs.Input.of_type_string("LCHName"),
            ssm_docs.Input.of_type_string("InstanceId"),
        ],
    )
    execute_powershell = ssm_docs.RunPowerShellScriptStep(
        self,
        "execute_delicense_script",
        name="Run delicense script",
        run_command=[ssm_docs.StringVariable(reference="C:\\cfn\\deactivate_license.ps1")],
        exit_on_failure=True,
    )
    terminate_instance = ssm_docs.AwsApiStep(
        self,
        "send_call_to_terminate_ec2",
        name="TerminateTheInstance",
        service=ssm_docs.AwsService.AUTO_SCALING,
        api_params={
            # pylint: disable=W1309
            "LifecycleHookName": f"{{{{ 'LCHName' }}}}",
            # pylint: disable=W1309
            "InstanceId": f"{{{{ 'InstanceId' }}}}",
            # pylint: disable=W1309
            "AutoScalingGroupName": f"{{{{ 'ASGName' }}}}",
            # "Api": "CompleteLifecycleAction",
            "LifecycleActionResult": "CONTINUE",
        },
        pascal_case_api="CompleteLifecycleAction",
        outputs=[],
        is_end=True,
    )

Help please :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions