cdklabs / cdklabs/cdk-ssm-documents

Running powershell script already placed in EC2

Open
#67 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
30
Forks
9
Avg merge
1d 16m
Merged PRs (30d)
7

Description

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 :)

Contributor guide

Open the contributing guide

Research direction

Start with the RunPowerShellScriptStep and StringVariable entry points shown in the issue, then read the runCommand type and AWS SSM Automation step requirements. Reproduce the deserialization and deployment failures with the provided examples. Done means the supported way to invoke the existing PowerShell script is confirmed and documented.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, powershell, python
Domain
cloud, devops
Issue type
Documentation
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.