cdk-ssm-documents
cdk-ssm-documents copied to clipboard
print(): maxAttempts step attribute not set, maxAttempts receives timeoutInSeconds value
- When setting just maxAttempts for a step, the step attribute is not set when printing the document content.\
default_values = {
"max_attempts": 1
}
# Define your steps...
describe_snapshot = ssm.AwsApiStep(
self,
f"{id}describeSnapshot",
name="describeSnapshot",
description="Describe the provided snapshot id",
service="ec2",
pascal_case_api="DescribeSnapshots",
api_params={"SnapshotIds": ["{{ SnapshotId }}"]},
outputs=[
ssm.Output(
name="VolumeId",
output_type=ssm.DataTypeEnum.STRING,
selector="$.Snapshots[0].VolumeId",
),
ssm.Output(
name="State",
output_type=ssm.DataTypeEnum.STRING,
selector="$.Snapshots[0].State",
),
],
is_end=False,
**default_values
)
produces:
...
mainSteps:
- description: Describe the provided snapshot id
name: describeSnapshot
action: aws:executeAwsApi
inputs:
Service: ec2
Api: DescribeSnapshots
SnapshotIds:
- '{{ SnapshotId }}'
outputs:
- Name: VolumeId
Selector: $.Snapshots[0].VolumeId
Type: String
- Name: State
Selector: $.Snapshots[0].State
Type: String
....
- When setting timeoutInSeconds for a step, maxAttempts is set:
In Python:
default_values = {
"timeout_seconds": 100
}
# Define your steps...
describe_snapshot = ssm.AwsApiStep(
self,
f"{id}describeSnapshot",
name="describeSnapshot",
description="Describe the provided snapshot id",
service="ec2",
pascal_case_api="DescribeSnapshots",
api_params={"SnapshotIds": ["{{ SnapshotId }}"]},
outputs=[
ssm.Output(
name="VolumeId",
output_type=ssm.DataTypeEnum.STRING,
selector="$.Snapshots[0].VolumeId",
),
ssm.Output(
name="State",
output_type=ssm.DataTypeEnum.STRING,
selector="$.Snapshots[0].State",
),
],
is_end=False,
**default_values
)
produces:
...
mainSteps:
- description: Describe the provided snapshot id
name: describeSnapshot
action: aws:executeAwsApi
inputs:
Service: ec2
Api: DescribeSnapshots
SnapshotIds:
- '{{ SnapshotId }}'
outputs:
- Name: VolumeId
Selector: $.Snapshots[0].VolumeId
Type: String
- Name: State
Selector: $.Snapshots[0].State
Type: String
maxAttempts: 100
....
- The reason that max_attempts is not getting set in your case is because the default for max_attempts is 1. If you would set that value to "2", then you will see that value reflected in the document. So in an effort to not clutter the document, if you set this value to 1, it is simply omitted. If you for some reason require this value set and disagree with the logic here, let me know what the reason is and we can make a change if necessary.
- This is indeed a bug - fixed in #39 (will be available in release v0.0.19)
My opinion is towards printing the exact content if I specify an option. If I need a compact version of the document for some reason (say I have reached the SSM document content maximum size and I can't deploy it, or individual's preference) then I could specify a compact=True flag while printing, i.e. print(compact=True). The logic could be flipped as well, i.e. allow for an expanded print that includes all the default values., i.e. print(expanded=True). This is what my team uses as not all developers are familiar with each action's default values, so these are explicitly set in each step.