Skip to content

Commit e706fd2

Browse files
committed
Update
1 parent c42967e commit e706fd2

File tree

2 files changed

+144
-9
lines changed

2 files changed

+144
-9
lines changed
Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
{
2+
"version": "1.2",
3+
"accountId": "681361479661",
4+
"configurationItemCaptureTime": "2017-04-05T22:23:11.677Z",
5+
"configurationItemStatus": "ResourceDiscovered",
6+
"configurationStateId": "1491430991677",
7+
"configurationItemMD5Hash": "7d83283adb8b966945d43cee39c7419c",
8+
"arn": "arn:aws:ec2:us-east-1:681361479661:instance/i-03402838daac1d611",
9+
"resourceType": "AWS::EC2::Instance",
10+
"resourceId": "i-03402838daac1d611",
11+
"awsRegion": "us-east-1",
12+
"availabilityZone": "us-east-1b",
13+
"resourceCreationTime": "2017-04-05T22:15:53.000Z",
14+
"tags": {},
15+
"relatedEvents": [
16+
"d3d87c29-bde3-4380-a7de-810f379246cc"
17+
],
18+
"relationships": [{
19+
"resourceType": "AWS::EC2::NetworkInterface",
20+
"resourceId": "eni-d055cfc4",
21+
"relationshipName": "Contains NetworkInterface"
22+
},
23+
{
24+
"resourceType": "AWS::EC2::SecurityGroup",
25+
"resourceId": "sg-fd215482",
26+
"relationshipName": "Is associated with SecurityGroup"
27+
},
28+
{
29+
"resourceType": "AWS::EC2::Subnet",
30+
"resourceId": "subnet-1aaccc7f",
31+
"relationshipName": "Is contained in Subnet"
32+
},
33+
{
34+
"resourceType": "AWS::EC2::Volume",
35+
"resourceId": "vol-0c24aa343c564eda8",
36+
"relationshipName": "Is attached to Volume"
37+
},
38+
{
39+
"resourceType": "AWS::EC2::VPC",
40+
"resourceId": "vpc-79b3ea1e",
41+
"relationshipName": "Is contained in Vpc"
42+
}
43+
],
44+
"configuration": {
45+
"instanceId": "i-03402838daac1d611",
46+
"imageId": "ami-22ce4934",
47+
"state": {
48+
"code": 16,
49+
"name": "running"
50+
},
51+
"privateDnsName": "ip-172-31-74-239.ec2.internal",
52+
"publicDnsName": "ec2-34-205-29-138.compute-1.amazonaws.com",
53+
"stateTransitionReason": "",
54+
"keyName": "ssm-key",
55+
"amiLaunchIndex": 0,
56+
"productCodes": [],
57+
"instanceType": "t2.micro",
58+
"launchTime": "2017-04-05T22:15:53.000Z",
59+
"placement": {
60+
"availabilityZone": "us-east-1b",
61+
"groupName": "",
62+
"tenancy": "default"
63+
},
64+
"monitoring": {
65+
"state": "disabled"
66+
},
67+
"subnetId": "subnet-1aaccc7f",
68+
"vpcId": "vpc-79b3ea1e",
69+
"privateIpAddress": "172.31.74.239",
70+
"publicIpAddress": "34.205.29.138",
71+
"architecture": "x86_64",
72+
"rootDeviceType": "ebs",
73+
"rootDeviceName": "/dev/xvda",
74+
"blockDeviceMappings": [{
75+
"deviceName": "/dev/xvda",
76+
"ebs": {
77+
"volumeId": "vol-0c24aa343c564eda8",
78+
"status": "attached",
79+
"attachTime": "2017-04-05T22:15:54.000Z",
80+
"deleteOnTermination": true
81+
}
82+
}],
83+
"virtualizationType": "hvm",
84+
"clientToken": "UuPNx1491430552432",
85+
"tags": [],
86+
"securityGroups": [{
87+
"groupName": "launch-wizard-2",
88+
"groupId": "sg-fd215482"
89+
}],
90+
"sourceDestCheck": true,
91+
"hypervisor": "xen",
92+
"networkInterfaces": [{
93+
"networkInterfaceId": "eni-d055cfc4",
94+
"subnetId": "subnet-1aaccc7f",
95+
"vpcId": "vpc-79b3ea1e",
96+
"description": "",
97+
"ownerId": "681361479661",
98+
"status": "in-use",
99+
"macAddress": "02:3e:c3:cb:e9:da",
100+
"privateIpAddress": "172.31.74.239",
101+
"privateDnsName": "ip-172-31-74-239.ec2.internal",
102+
"sourceDestCheck": true,
103+
"groups": [{
104+
"groupName": "launch-wizard-2",
105+
"groupId": "sg-fd215482"
106+
}],
107+
"attachment": {
108+
"attachmentId": "eni-attach-e8d5c971",
109+
"deviceIndex": 0,
110+
"status": "attached",
111+
"attachTime": "2017-04-05T22:15:53.000Z",
112+
"deleteOnTermination": true
113+
},
114+
"association": {
115+
"publicIp": "34.205.29.138",
116+
"publicDnsName": "ec2-34-205-29-138.compute-1.amazonaws.com",
117+
"ipOwnerId": "amazon"
118+
},
119+
"privateIpAddresses": [{
120+
"privateIpAddress": "172.31.74.239",
121+
"privateDnsName": "ip-172-31-74-239.ec2.internal",
122+
"primary": true,
123+
"association": {
124+
"publicIp": "34.205.29.138",
125+
"publicDnsName": "ec2-34-205-29-138.compute-1.amazonaws.com",
126+
"ipOwnerId": "amazon"
127+
}
128+
}],
129+
"ipv6Addresses": []
130+
}],
131+
"ebsOptimized": true,
132+
"enaSupport": true
133+
},
134+
"supplementaryConfiguration": {}
135+
}

Config/Finding-Outdated-Instance-Types/lamba_function.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,28 @@
77

88
def lambda_handler(event, context):
99
invoking_event = json.loads(event['invokingEvent'])
10-
rule_parameters = json.loads(event['ruleParameters'])
10+
rule_parameters = json.loads(event['ruleParameters']) # i.e. 't2.micro'
1111

1212
compliance_value = 'NOT_APPLICABLE'
13+
item = invoking_event['configurationItem'] # one per AWS resource
1314

14-
if is_applicable(invoking_event['configurationItem'], event):
15-
compliance_value = evaluate_compliance(
16-
invoking_event['configurationItem'], rule_parameters)
15+
if is_applicable(item, event):
16+
compliance_value = evaluate_compliance(item, rule_parameters)
1717

1818
config.put_evaluations(
1919
Evaluations=[
2020
{
21-
'ComplianceResourceType': invoking_event['configurationItem']['resourceType'],
22-
'ComplianceResourceId': invoking_event['configurationItem']['resourceId'],
21+
'ComplianceResourceType': item['resourceType'],
22+
'ComplianceResourceId': item['resourceId'],
2323
'ComplianceType': compliance_value,
24-
'OrderingTimestamp': invoking_event['configurationItem']['configurationItemCaptureTime']
24+
'OrderingTimestamp': item['configurationItemCaptureTime']
2525
},
2626
],
2727
ResultToken=event['resultToken'])
2828

2929

30-
def is_applicable(config_item, event):
31-
status = config_item['configurationItemStatus']
30+
def is_applicable(item, event):
31+
status = item['configurationItemStatus']
3232
event_left_scope = event['eventLeftScope']
3333
test = ((status in ['OK', 'ResourceDiscovered']) and
3434
event_left_scope is False)

0 commit comments

Comments
 (0)