-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support for putting configuration in parameter store to enable Lambda…
… faults via libraries
- Loading branch information
Showing
5 changed files
with
249 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import * as cdk from "aws-cdk-lib"; | ||
import { Construct } from "constructs"; | ||
import { StackProps, Stack } from "aws-cdk-lib"; | ||
import { aws_fis as fis } from "aws-cdk-lib"; | ||
import { aws_iam as iam } from "aws-cdk-lib"; | ||
|
||
export class LambdaChaosExperiments extends Stack { | ||
constructor(scope: Construct, id: string, props?: StackProps) { | ||
super(scope, id, props); | ||
|
||
// Import FIS Role, Stop Condition, and other required parameters | ||
const importedFISRoleArn = cdk.Fn.importValue("FISIamRoleArn"); | ||
const importedStopConditionArn = cdk.Fn.importValue("StopConditionArn"); | ||
const importedSSMAPutParameterStoreRoleArn = cdk.Fn.importValue( | ||
"SSMAPutParameterStoreRoleArn" | ||
); | ||
const importedPutParameterStoreSSMADocName = cdk.Fn.importValue( | ||
"PutParameterStoreSSMADocName" | ||
); | ||
|
||
const importedParameterName = this.node.tryGetContext("ssm_parameter_name"); | ||
|
||
// Targets - empty since SSMA defines its own targets | ||
|
||
// Actions | ||
const startAutomation = { | ||
actionId: "aws:ssm:start-automation-execution", | ||
description: "Put config into parameter store to enable Lambda Chaos.", | ||
parameters: { | ||
documentArn: `arn:aws:ssm:${this.region}:${ | ||
this.account | ||
}:document/${importedPutParameterStoreSSMADocName.toString()}`, | ||
documentParameters: JSON.stringify({ | ||
DurationMinutes: "PT1M", | ||
AutomationAssumeRole: importedSSMAPutParameterStoreRoleArn.toString(), | ||
ParameterName: importedParameterName.toString(), | ||
ParameterValue: "{ \"delay\": 500, \"is_enabled\": true, \"error_code\": 404, \"exception_msg\": \"This is chaos\", \"rate\": 1, \"fault_type\": \"exception\"}", | ||
RollbackValue: "{ \"delay\": 500, \"is_enabled\": false, \"error_code\": 404, \"exception_msg\": \"This is chaos\", \"rate\": 1, \"fault_type\": \"exception\"}" | ||
}), | ||
maxDuration: "PT5M", | ||
}, | ||
}; | ||
|
||
// Experiments | ||
const templateInjectS3AccessDenied = new fis.CfnExperimentTemplate( | ||
this, | ||
"fis-template-inject-lambda-fault", | ||
{ | ||
description: "Inject faults into Lambda function using chaos-lambda library", | ||
roleArn: importedFISRoleArn.toString(), | ||
stopConditions: [ | ||
{ | ||
source: "aws:cloudwatch:alarm", | ||
value: importedStopConditionArn.toString(), | ||
}, | ||
], | ||
tags: { | ||
Name: "Inject fault to Lambda functions", | ||
Stackname: this.stackName, | ||
}, | ||
actions: { | ||
ssmaAction: startAutomation, | ||
}, | ||
targets: {}, | ||
} | ||
); | ||
} | ||
} |
114 changes: 114 additions & 0 deletions
114
lib/fis-upload-ssm-docs/documents/ssma-put-config-parameterstore.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
--- | ||
#================================================== | ||
# SSM Automation Document / Runbook: | ||
# Defines the configuration as well as the | ||
# the steps to be run by SSM Automation | ||
#================================================== | ||
|
||
description: | | ||
### Document Name - ParameterStore-FIS-Automation | ||
## What does this document do? | ||
This document stores a particular configuration to SSM Parameter store. | ||
https://docs.aws.amazon.com/systems-manager/latest/userguide/systems-manager-parameter-store.html | ||
## Security Risk | ||
Low: This is not a fault per se, but a configuration change.The change should be restricted by a strict IAM role that only allows changing a particular ParameterName. https://docs.aws.amazon.com/systems-manager/latest/userguide/sysman-paramstore-access.html | ||
## Input Parameters | ||
* AutomationAssumeRole: (Optional) The ARN of the role that allows Automation to perform the actions on your behalf. | ||
* ParameterName: (Required) The name of the parameter to modify. | ||
* ParameterValue: (Required) The value of the parameter. | ||
* RollbackValue: (Required) The value of the parameter to roll-back to. | ||
* Type: (Optional) The type of parameter. String, StringList, or SecureString. Default String. | ||
* DurationMinutes: (Optional) ** Default 1 minute ** Maximum duration the fault can exist for. | ||
## Supports Rollback | ||
Yes. The configuration is reverted to a . | ||
## Cancellation behaviour | ||
The parameter value is rollback to RollbackValue. | ||
## Output Parameters | ||
This document has no outputs. | ||
## Minimum Permissions Required | ||
* ssm:PutParameter | ||
## Additional Permissions for logging | ||
* logs:CreateLogStream | ||
* logs:CreateLogGroup | ||
* logs:PutLogEvents | ||
* logs:DescribeLogGroups | ||
* logs:DescribeLogStreams | ||
schemaVersion: "0.3" | ||
|
||
#================================================== | ||
# Role assumed my the automation document / runbook | ||
#================================================== | ||
assumeRole: "{{ AutomationAssumeRole }}" | ||
|
||
#================================================== | ||
# SSM automation document parameters | ||
#================================================== | ||
|
||
parameters: | ||
ParameterName: | ||
type: String | ||
description: "(Required) The name of the parameter to modify." | ||
ParameterValue: | ||
type: String | ||
description: "(Required) The value of the parameter." | ||
RollbackValue: | ||
type: String | ||
description: "(Required) The value of the parameter to roll-back to." | ||
ParameterType: | ||
type: String | ||
description: "(Optional) The type of parameter. String, StringList, or SecureString." | ||
default: "String" | ||
DurationMinutes: | ||
type: String | ||
description: "The duration - in ISO-8601 format - until rollback. (Required)" | ||
default: "PT1M" | ||
AutomationAssumeRole: | ||
type: String | ||
description: | ||
"(Optional) The ARN of the role that allows Automation to perform | ||
the actions on your behalf." | ||
|
||
#================================================== | ||
# Automation steps | ||
#================================================== | ||
|
||
mainSteps: | ||
- name: putParameter | ||
description: Adding value to a particular parameter | ||
onFailure: "step:rollback" | ||
onCancel: "step:rollback" | ||
action: "aws:executeAwsApi" | ||
inputs: | ||
Service: ssm | ||
Api: PutParameter | ||
Name: '{{ ParameterName }}' | ||
Value: '{{ ParameterValue }}' | ||
Type: '{{ ParameterType }}' | ||
Overwrite: true | ||
|
||
- name: sleep | ||
action: aws:sleep | ||
onFailure: "step:rollback" | ||
onCancel: "step:rollback" | ||
inputs: | ||
Duration: "{{ DurationMinutes }}" | ||
|
||
- name: rollback | ||
description: Rolling back value to a particular parameter | ||
action: "aws:executeAwsApi" | ||
inputs: | ||
Service: ssm | ||
Api: PutParameter | ||
Name: '{{ ParameterName }}' | ||
Value: '{{ RollbackValue }}' | ||
Type: '{{ ParameterType }}' | ||
Overwrite: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters