generate_template_example
Create example AWS Fault Injection Service experiment templates to test system resilience by injecting failures into specified AWS resources and actions.
Instructions
Generate an example AWS FIS experiment template for a given target and action type.
Args:
target_type: Target resource type (default: aws:ec2:instance)
action_type: Action type to perform (default: aws:ec2:stop-instances)
region: AWS region to use (default: us-east-1)
Returns:
JSON string containing an example template configuration
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| target_type | No | aws:ec2:instance | |
| action_type | No | aws:ec2:stop-instances | |
| region | No | us-east-1 |
Implementation Reference
- aws_fis_mcp/tools.py:343-402 (handler)The handler function that executes the logic for the 'generate_template_example' tool, generating a sample AWS FIS experiment template JSON.def generate_template_example( target_type: str = "aws:ec2:instance", action_type: str = "aws:ec2:stop-instances", region: str = "us-east-1" ) -> str: """ Generate an example AWS FIS experiment template for a given target and action type. Args: target_type: Target resource type (default: aws:ec2:instance) action_type: Action type to perform (default: aws:ec2:stop-instances) region: AWS region to use (default: us-east-1) Returns: JSON string containing an example template configuration """ try: # Example template structure template = { "description": f"Example experiment template for {action_type} on {target_type}", "targets": { "MyTargets": { "resourceType": target_type, "resourceArns": ["REPLACE_WITH_ACTUAL_RESOURCE_ARN"], "selectionMode": "ALL" } }, "actions": { "MyAction": { "actionId": action_type, "parameters": {}, "targets": { "Instances": "MyTargets" } } }, "stopConditions": [ { "source": "none" } ], "roleArn": "REPLACE_WITH_ACTUAL_ROLE_ARN", "tags": { "Name": f"Example-{target_type}-{action_type}" } } # Add common parameters based on action type if action_type == "aws:ec2:stop-instances": template["actions"]["MyAction"]["parameters"] = { "startAfter": "PT0M" } elif action_type == "aws:ec2:reboot-instances": template["actions"]["MyAction"]["parameters"] = { "startAfter": "PT0M" } return json.dumps(template, indent=2) except Exception as e: return f"Error generating template example: {str(e)}"
- aws_fis_mcp/server.py:34-34 (registration)Registers the generate_template_example handler as an MCP tool using FastMCP's app.tool() decorator.app.tool()(generate_template_example)
- aws_fis_mcp/server.py:7-19 (registration)Imports the generate_template_example function from tools.py for use in tool registration.from aws_fis_mcp.tools import ( list_experiment_templates, get_experiment_template, list_experiments, get_experiment, start_experiment, stop_experiment, create_experiment_template, delete_experiment_template, list_action_types, generate_template_example, set_write_mode, )