This file contains hidden or 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
#!/usr/bin/env bash | |
bucket_name=joey-my-sam-app | |
project_dir=$HOME/working/cloud-computing/lambda-demos | |
# packaging application | |
sam package \ | |
--output-template-file $project_dir/output/packaged.yaml \ | |
--s3-bucket $bucket_name > /dev/null |
This file contains hidden or 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
AWSTemplateFormatVersion: 2010-09-09 | |
Transform: 'AWS::Serverless-2016-10-31' | |
#Parameters: | |
# LambdaExecutionRole: | |
Resources: | |
ruleEvaluationDev: | |
Type: 'AWS::Serverless::Function' | |
Properties: | |
FunctionName: 'cost-controller-function' |
This file contains hidden or 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
def shutdown_ec2_instance(ec2_client, instanceId): | |
log.info("shutting down instance-id :" + instanceId) | |
ec2_client.terminate_instances( | |
InstanceIds=[ | |
instanceId | |
] | |
) |
This file contains hidden or 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
def validate_tag_name(tags: List[str]): | |
required_tag_names: Sequence[str] = ['environment', 'owner', 'projectName', 'costCentre'] | |
is_valid = True | |
for required_tag in required_tag_names: | |
if required_tag not in tags: | |
is_valid = False | |
break | |
return is_valid |
This file contains hidden or 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
def evaluate_ec2_instance(ec2_client, event): | |
instance_id = event['detail']['instance-id'] | |
instance_state = event['detail']['state'] | |
''' | |
only perform this evaluation rule when starting an new instance | |
check if instance state is pending then try to perfrom evaluation | |
''' | |
if instance_state != 'pending': | |
log.info('current state : ' + instance_state) |
This file contains hidden or 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
def lambda_handler(event, context): | |
log.info(" evaluating tags of ec2 instance") | |
if not event: | |
log.info("event is not valid") | |
else: | |
evaluate_ec2_instance(ec2_client, event) |
This file contains hidden or 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
Resources: | |
ruleEvaluationDev: | |
Type: 'AWS::Serverless::Function' | |
Properties: | |
FunctionName: 'cost-controller-function' | |
Description: 'Integrating lambda with Parameter Store' | |
Handler: 'cost_controller.cost_controller_handlers.lambda_handler' | |
Runtime: 'python3.6' | |
Role: 'arn:aws:iam::<your_account_id_here>:role/service-role/my-rule-evaluation-function' | |
Timeout: 5 |
This file contains hidden or 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
from typing import Sequence | |
import logging as log | |
import boto3 | |
from typing import List | |
from botocore.exceptions import ClientError | |
from typing import Dict | |
ec2_client = boto3.client('ec2') | |
sns_client = boto3.client('sns') |
This file contains hidden or 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
keyspace: perftesting | |
keyspace_definition: | |
CREATE KEYSPACE perftesting WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': 3}; | |
table: users | |
table_definition: | |
CREATE TABLE users ( |
This file contains hidden or 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
CASSANDRA_VERION=3.11 | |
CASSANDRA_NODES=( | |
CASSANDRA_1 \ | |
CASSANDRA_2 \ | |
CASSANDRA_3 | |
) | |
# setup cassandra 3.11 | |
# assume you have docker installed. |
NewerOlder