Skip to content

Commit 3eb91ae

Browse files
nanalakshmananmmendonca3
authored andcommitted
New Systems Manager Automation documents (10) authored since repo was made… (#19)
* New Systems Manager Automation documents authored since repo was made public * Updating AMI Ids in defaults.cfg
1 parent 9e11c9d commit 3eb91ae

File tree

81 files changed

+7106
-2
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+7106
-2
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Change Standby state of instances within an autoscaling group with approval
2+
3+
## Document Design
4+
5+
Refer to schema.json
6+
7+
### Steps
8+
9+
1. Require approval for further execution
10+
* Once execution is approved, the next steps will occur
11+
2. Create CloudFormation Template
12+
* CloudFormation template will create a lambda function that can change the standby state of an instance in an ASG
13+
3. Execute lambda
14+
* Lambda function take parameters instance ID and the state to put the instance into (either EitherStandby or ExitStandby)
15+
4. Delete CloudFormation Template
16+
* Deleting the CF template will destroy any created IAM roles as well as the deployed Lambda
17+
18+
## Tests
19+
20+
### tests.py
21+
22+
The tests for both Enter and Exit standby are defined in this file, with separate test functions for each action.
23+
24+
### Building Document and Test
25+
26+
1. Change directory to /Automation/ASGChangeStandbyState/
27+
2. Run ```make```
28+
3. In the AWS console, navigate to the EC2 screen and select "Documents" under "SYSTEMS MANAGER SHARED RESOURCES" on the left-hand menu.
29+
4. Click Create Document
30+
5. Enter the name awstest-ASGEnterStandby
31+
6. Select "Automation" as the document type
32+
7. Copy and paste the contents of /Automation/ASGChangeStandbyState/Output/aws-ASGEnterStandby.json into the Content text area.
33+
8. Click "Create Document"
34+
9. Do the same for the exit standby document, substituting "awstest-ASGExitStandby" for the document name, and copy the contents of
35+
/Automation/ASGChangeStandbyState/Output/aws-ASGExitStandby.json into the document.
36+
10. Change directory to /Automation/ASGChangeStandbyStateWithApproval/ and run ```python tests.py```
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"schemaVersion": "0.3",
3+
"assumeRole": "{{AutomationAssumeRole}}",
4+
"description": "Systems Manager Automation - Change the standby state of an EC2 instance in an auto-scaling group with approval",
5+
"parameters": {
6+
"InstanceId": {
7+
"type": "String",
8+
"description": "ID of the EC2 Instance to change standby state for within ASG"
9+
},
10+
"LambdaRoleArn": {
11+
"default": "",
12+
"type": "String",
13+
"description": "The ARN of the role that allows Lambda created by Automation to perform the actions on your behalf"
14+
},
15+
"StackName": {
16+
"default": "asg-state-change-lambda-cfn-stack",
17+
"type": "String",
18+
"description": "Name for the CloudFormation stack which creates the necessary lambda function to change ASG state"
19+
},
20+
"LambdaFunctionName": {
21+
"default": "asg-state-change-lambda-function",
22+
"type": "String",
23+
"description": "Name for the lambda function which can change the ASG state"
24+
},
25+
"AutomationAssumeRole": {
26+
"default": "",
27+
"type": "String",
28+
"description": "The ARN of the role that allows Automation to perform the actions on your behalf."
29+
}
30+
},
31+
"mainSteps": []
32+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"description": "Systems Manager Automation - Put an EC2 instance in an auto-scaling group in Standby mode, with approval",
3+
"schemaVersion": "0.3",
4+
"assumeRole": "{{AutomationAssumeRole}}",
5+
"parameters": {
6+
"AutomationAssumeRole": {
7+
"type": "String",
8+
"description": "The ARN of the role that allows Automation to perform the actions on your behalf.",
9+
"default": ""
10+
},
11+
"LambdaRoleArn": {
12+
"type": "String",
13+
"description": "The ARN of the role that allows Lambda created by Automation to perform the actions on your behalf",
14+
"default": ""
15+
},
16+
"InstanceId": {
17+
"type": "String",
18+
"description": "ID of the EC2 Instance to change standby state for within ASG"
19+
},
20+
"Approvers": {
21+
"type": "StringList",
22+
"description": "IAM user or user arn of approvers for the automation action"
23+
},
24+
"SNSTopicArn": {
25+
"type": "String",
26+
"description": "The SNS topic ARN that you are using to get notifications on about EC2 retirement notifications. The SNS topic name must start with Automation."
27+
}
28+
},
29+
"mainSteps": [
30+
{
31+
"name": "approveStateChange",
32+
"action": "aws:approve",
33+
"maxAttempts": 1,
34+
"onFailure": "Abort",
35+
"inputs": {
36+
"NotificationArn": "{{SNSTopicArn}}",
37+
"Message": "Approval required to change ASG instance state",
38+
"MinRequiredApprovals": 1,
39+
"Approvers": "{{Approvers}}"
40+
}
41+
},
42+
{
43+
"name":"changeASGInstanceStateAutomation",
44+
"action":"aws:executeAutomation",
45+
"maxAttempts":1,
46+
"timeoutSeconds":120,
47+
"onFailure":"Abort",
48+
"inputs":{
49+
"DocumentName":"AWS-ASGEnterStandby",
50+
"RuntimeParameters":{
51+
"AutomationAssumeRole": ["{{AutomationAssumeRole}}"],
52+
"LambdaRoleArn": ["{{LambdaRoleArn}}"],
53+
"InstanceId": ["{{InstanceId}}"]
54+
}
55+
}
56+
}
57+
]
58+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{
2+
"description": "Systems Manager Automation - Take an EC2 instance in an auto-scaling group out of Standby mode, with approval",
3+
"schemaVersion": "0.3",
4+
"assumeRole": "{{AutomationAssumeRole}}",
5+
"parameters": {
6+
"AutomationAssumeRole": {
7+
"type": "String",
8+
"description": "The ARN of the role that allows Automation to perform the actions on your behalf.",
9+
"default": ""
10+
},
11+
"LambdaRoleArn": {
12+
"type": "String",
13+
"description": "The ARN of the role that allows Lambda created by Automation to perform the actions on your behalf",
14+
"default": ""
15+
},
16+
"InstanceId": {
17+
"type": "String",
18+
"description": "ID of the EC2 Instance to change standby state for within ASG"
19+
},
20+
"Approvers": {
21+
"type": "StringList",
22+
"description": "IAM user or user arn of approvers for the automation action"
23+
},
24+
"SNSTopicArn": {
25+
"type": "String",
26+
"description": "The SNS topic ARN that you are using to get notifications on about EC2 retirement notifications. The SNS topic name must start with Automation."
27+
}
28+
},
29+
"mainSteps": [
30+
{
31+
"name": "approveStateChange",
32+
"action": "aws:approve",
33+
"maxAttempts": 1,
34+
"onFailure": "Abort",
35+
"inputs": {
36+
"NotificationArn": "{{SNSTopicArn}}",
37+
"Message": "Approval required to change ASG instance state",
38+
"MinRequiredApprovals": 1,
39+
"Approvers": "{{Approvers}}"
40+
}
41+
},
42+
{
43+
"name":"changeASGInstanceStateAutomation",
44+
"action":"aws:executeAutomation",
45+
"maxAttempts":1,
46+
"timeoutSeconds":120,
47+
"onFailure":"Abort",
48+
"inputs":{
49+
"DocumentName":"AWS-ASGExitStandby",
50+
"RuntimeParameters":{
51+
"AutomationAssumeRole": ["{{AutomationAssumeRole}}"],
52+
"LambdaRoleArn": ["{{LambdaRoleArn}}"],
53+
"InstanceId": ["{{InstanceId}}"]
54+
}
55+
}
56+
}
57+
]
58+
}
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
---
2+
AWSTemplateFormatVersion: '2010-09-09'
3+
Conditions:
4+
SSHKeySpecified:
5+
!And
6+
- !Not [!Equals [!Ref KeyName, '']]
7+
- !Not [!Equals [!Ref KeyName, 'undefined']]
8+
Description: Test stack for SSM Automation - ASG
9+
Outputs:
10+
ASGName:
11+
Description: Name of autoscaling group
12+
Value: !Ref ASG
13+
SNSTopicArn:
14+
Description: ARN for the created SNS topic
15+
Value:
16+
Ref: SNSTopic
17+
Parameters:
18+
AMI:
19+
Description: AMI ID for instances.
20+
Type: String
21+
AssociatePublicIpAddress:
22+
Default: 'false'
23+
Description: Should a public IP be automatically associated with launched instances?
24+
Type: String
25+
InstanceType:
26+
Default: m3.medium
27+
Description: Type of instances to launch
28+
Type: String
29+
KeyName:
30+
Default: ''
31+
Description: Name of an existing EC2-VPC KeyPair
32+
Type: String
33+
Subnets:
34+
Description: Subnets in which the servers will be deployed
35+
Type: List<AWS::EC2::Subnet::Id>
36+
Resources:
37+
InstanceProfile:
38+
Properties:
39+
Path: "/"
40+
Roles: [!Ref ServerRole]
41+
Type: AWS::IAM::InstanceProfile
42+
SNSTopic:
43+
Type: AWS::SNS::Topic
44+
Properties:
45+
DisplayName: Automation Approval Topic for putting instances in ASG into Standby mode
46+
TopicName: Automation_ASG_Standby_Approval
47+
ASG:
48+
Properties:
49+
DesiredCapacity: 2
50+
LaunchConfigurationName: !Ref LaunchConfig
51+
MaxSize: 2
52+
MinSize: 1
53+
VPCZoneIdentifier: !Ref Subnets
54+
Type: AWS::AutoScaling::AutoScalingGroup
55+
LaunchConfig:
56+
Properties:
57+
IamInstanceProfile: !Ref InstanceProfile
58+
ImageId: !Ref AMI
59+
InstanceType: !Ref InstanceType
60+
KeyName: !If [SSHKeySpecified, !Ref KeyName, !Ref "AWS::NoValue"]
61+
Type: AWS::AutoScaling::LaunchConfiguration
62+
ServerRole:
63+
Properties:
64+
AssumeRolePolicyDocument:
65+
Statement:
66+
- Action:
67+
- sts:AssumeRole
68+
Effect: Allow
69+
Principal:
70+
Service: [ec2.amazonaws.com]
71+
Version: '2012-10-17'
72+
ManagedPolicyArns:
73+
- arn:aws:iam::aws:policy/service-role/AmazonEC2RoleforSSM
74+
- arn:aws:iam::aws:policy/AutoScalingFullAccess
75+
- arn:aws:iam::aws:policy/AmazonEC2ReadOnlyAccess
76+
Path: "/"
77+
Type: AWS::IAM::Role

Documents/Automation/ASGChangeStandbyStateWithApproval/Tests/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)