Skip to content

Commit

Permalink
Fixed code
Browse files Browse the repository at this point in the history
  • Loading branch information
Drew J. Sonne committed Jun 25, 2017
1 parent e1c053b commit 81f5042
Showing 1 changed file with 60 additions and 75 deletions.
135 changes: 60 additions & 75 deletions docs/awsconfig.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,87 +18,72 @@ Create a new class, write it in a function to be set as the lambda handler, and
Configuration Change Rule
=========================

.. code-block:: python
from awsconfig_lambdahelper.configrule import AWSConfigRule
from awsconfig_lambdahelper.evaluation import CompliantEvaluation,NonCompliantEvaluation
# A schedule AWS config rule
class MyCustomConfigurationChangeRule(AWSConfigRule):
def find_violation_config_change(self, config, rule_parameters):
rule_responses = apply_my_rule_to_a_resource(config)
response = []
for violation in rule_responses:
if violation['failed']:
response.append(
NonCompliantEvaluation(
Annotation="This failed because of a good reason."
)
)
else:
# There's no need to set the resource id or type, as the library is aware of those
# values and will apply them automatically.
response.append(CompliantEvaluation())
return response
# Lambda entrypoint
def lambda_handler(event, context):
my_rule = MyCustomConfigurationChangeRule(
applicable_resources=["AWS::EC2::Instance"]
)
my_rule.lambda_handler(event, context)

>>> from awsconfig_lambdahelper.configrule import AWSConfigRule
>>> from awsconfig_lambdahelper.evaluation import CompliantEvaluation,NonCompliantEvaluation
>>>
>>> # A schedule AWS config rule
>>> class MyCustomConfigurationChangeRule(AWSConfigRule):
... def find_violation_config_change(self, config, rule_parameters):
... rule_responses = apply_my_rule_to_a_resource(config)
... response = []
... for violation in rule_responses:
... if violation['failed']:
... response.append(
... NonCompliantEvaluation(
... Annotation="This failed because of a good reason."
... )
... )
... else:
... # There's no need to set the resource id or type, as the library is aware of those
... # values and will apply them automatically.
... response.append(CompliantEvaluation())
... return response
>>>
>>> # Lambda entrypoint
>>> def lambda_handler(event, context):
... my_rule = MyCustomConfigurationChangeRule(
... applicable_resources=["AWS::EC2::Instance"]
... )
... my_rule.lambda_handler(event, context)

==============
Scheduled Rule
==============

.. code-block:: python
from awsconfig_lambdahelper.configrule import AWSConfigRule
from awsconfig_lambdahelper.evaluation import CompliantEvaluation,NonCompliantEvaluation
# A schedule AWS config rule
class MyCustomScheduledConfigRule(AWSConfigRule):
def find_violation_scheduled(self, ruleParameters, accountId):
rule_responses = apply_my_rules()
response = []
for violation in rule_responses:
if violation['failed']:
response.append(
# Scheduled rules are not in response to a config change, so you need to tell AWS Config what
# resources you were looking at.
CompliantEvaluation(
ResourceType=violation['my_resource_type'],
ResourceId=violation['my_resource_id']
)
)
else:
response.append(
NonCompliantEvaluation(
ResourceType=violation['my_resource_type'],
ResourceId=violation['my_resource_id'],
Annotation="This failed because of a good reason."
)
)
return response
# Lambda entrypoint
def lambda_handler(event, context):

my_rule = MyCustomScheduledConfigRule(
applicable_resources=["AWS::EC2::Instance"]
)
my_rule.lambda_handler(event, context)
>>> from awsconfig_lambdahelper.configrule import AWSConfigRule
>>> from awsconfig_lambdahelper.evaluation import CompliantEvaluation,NonCompliantEvaluation
>>> # A schedule AWS config rule
>>> class MyCustomScheduledConfigRule(AWSConfigRule):
... def find_violation_scheduled(self, rule_parameters, account_id):
... rule_responses = apply_my_rules()
... response = []
... for violation in rule_responses:
... if violation['failed']:
... response.append(
... # Scheduled rules are not in response to a config change, so you need to tell AWS Config what
... # resources you were looking at.
... CompliantEvaluation(
... ResourceType=violation['my_resource_type'],
... ResourceId=violation['my_resource_id']
... )
... )
... else:
... response.append(
... NonCompliantEvaluation(
... ResourceType=violation['my_resource_type'],
... ResourceId=violation['my_resource_id'],
... Annotation="This failed because of a good reason."
... )
... )
... return response
>>>
>>> # Lambda entrypoint
>>> def lambda_handler(event, context):
... my_rule = MyCustomScheduledConfigRule(
... applicable_resources=["AWS::EC2::Instance"]
... )
... my_rule.lambda_handler(event, context)


0 comments on commit 81f5042

Please sign in to comment.