- Newest
- Most votes
- Most comments
hi,
Great work! You're building an SSM automation to delete an IAM user from each group.
Basically, Need Lambda function to iterate the GroupNames.
For the output section where you're trying to extract all GroupName values from the Groups array, you need to invoke a Lambda function to iterate over all groups, because SSM doesn’t support wildcards like [] in JSONPath to extract multiple values directly.
https://docs.aws.amazon.com/systems-manager/latest/userguide/automation-action-outputs-inputs.html
*[ outputs:
- Name: GroupNames
Selector: $.Groups[].GroupName ---------> SSM is not supporting [ ], can't extract all GroupName field.
Type: StringList
] *
so, we need Lambda Function to iterate the group names"->
[
def lambda_handler(event, context):
groups = event.get("Groups", [ ])
group_names = [group["GroupName"] for group in groups if "GroupName" in group]
return {
"GroupNames": group_names
}
then in your SSM automation doc invoke Lambda and set the output:->
outputs:
-
Name: GroupNames
Selector: $.Payload.GroupNames ----> [The Payload is a standard key in the response returned by Lambda.]
Type: StringList
This way, you'll have the group names processed by the Lambda function, and you'll be able to correctly iterate through them in subsequent steps.
Best,
The error you're encountering is due to an incorrect syntax in the output selector for the GetUserGroups step. To resolve this issue, you need to modify the Selector in the outputs section of the GetUserGroups step.
Instead of:
Selector: $.Groups[].GroupName
You should use:
Selector: "Groups[*].GroupName"
This change will correctly select the GroupName from each Group in the response. The "[*]" syntax is used to iterate over all elements in the Groups array, and ".GroupName" selects the GroupName property from each group.
Also, make sure that the Type is set to StringList, as you have it in your current configuration.
Your corrected GetUserGroups step should look like this:
- name: GetUserGroups action: aws:executeAwsApi nextStep: RemoveUserFromGroups isEnd: false inputs: Service: iam Api: ListGroupsForUser UserName: '{{ UserName }}' outputs: - Name: GroupNames Selector: "Groups[*].GroupName" Type: StringList
This modification should resolve the "Output Selector must be a valid JSONPath expression" error you're encountering. The rest of your document structure looks correct for the task of deleting an IAM user after removing them from all groups.
Sources
Configuring inputs and outputs for your actions - AWS Systems Manager
AWS Service Catalog Service Actions - AWS Service Catalog
Output selector Groups[].GroupName is invalid. Selector contains only the following JSONPath operations: [Dot-notated child (.), Deep-scan (..), Array index ([])] or filtering expressions using only ==, !=, <, >, <=, or >= operators. The following JSONPath operators: ',' ':' '', regular expressions, '&&' and '||' in filter expressions, and functions such as length() are currently not supported.