Skip to content

Commit

Permalink
Fixed SNS issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Higherings committed Feb 21, 2020
1 parent ffb34dd commit f7b46c5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions autoComputeOptimizer-template.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# igarcia 2020-02
# Version 0.7
# Version 0.8
# Automation for Compute Optimizer Recommendations
# Create a Scheduled Lambda with CloudWatch Event to implements Compute Optimizer Recommendations changes on EC2 Instances
# Resources to create: Lambda, CloudWatch Event, IAM Role, SNS Topic
Expand Down Expand Up @@ -96,7 +96,7 @@ Parameters: #Default Parameters Values
pCorreo:
Type: String
Description: "E-mail address for Notifications"
Default: "myemail@mydomain.com"
Default: "not@notify.me"
MaxLength: 50
MinLength: 5
ConstraintDescription: "Please write a valid e-mail address."
Expand Down Expand Up @@ -210,6 +210,7 @@ Resources:
TAGBUSQUEDA: !Ref pTagBusqueda
TAGVALOR: !Ref pTagValor
TOPIC: !Ref TemplateSNS
CORREO: !Ref pCorreo
FunctionName: !Join [ "-", [ "AutoComputeOptimizerLambda", !Ref TemplateAmbiente ] ]
Role: !GetAtt TemplateRole.Arn
Timeout: 800
Expand Down
8 changes: 5 additions & 3 deletions autocomputeoptimizer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# igarcia 2020-02
# Version 0.7
# Version 0.8
# Automation for Compute Optimizer Recommendations
# It will change the EC2 Instance Type to a Recommendation of the AWS Compute Optimizer Service and send an email about it
# It won't do anything to AutoScaling Group's Instances
Expand All @@ -15,6 +15,7 @@
TAGBUSQUEDA = os.environ['TAGBUSQUEDA']
TAGVALOR = os.environ['TAGVALOR']
TOPIC = os.environ['TOPIC']
CORREO = os.environ['CORREO']

ec2 = boto3.resource('ec2')
co_client = boto3.client('compute-optimizer')
Expand Down Expand Up @@ -100,11 +101,12 @@ def lambda_handler(event, context):
total+=1
cambios = cambios + review_compute_optimizer_recos(instance)

the_topic = sns.Topic(TOPIC)
the_message = "Se realizaron "+cambios+" cambios con éxito de un total de "+total+" sugeridos.\nRevise el log de la Lambda para conocer las instancias afectadas."
print("Se realizaron {} cambios con éxito de un total de {} sugeridos.".format(cambios,total))
try:
response = the_topic.publish(Subject="AutoComputeOptimizer Notification", Message=the_message)
if CORREO != "not@notify.me":
the_topic = sns.Topic(TOPIC)
response = the_topic.publish(Subject="AutoComputeOptimizer Notification", Message=the_message)
except:
print(response)
print("Fallo al enviar mensaje por SNS.")
Expand Down

0 comments on commit f7b46c5

Please sign in to comment.