Skip to content

Instantly share code, notes, and snippets.

View anhtv08's full-sized avatar

Joey Trang anhtv08

View GitHub Profile
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
def shutdown_ec2_instance(ec2_client, instanceId):
log.info("shutting down instance-id :" + instanceId)
ec2_client.terminate_instances(
InstanceIds=[
instanceId
]
)
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
AWSTemplateFormatVersion: 2010-09-09
Transform: 'AWS::Serverless-2016-10-31'
#Parameters:
# LambdaExecutionRole:
Resources:
ruleEvaluationDev:
Type: 'AWS::Serverless::Function'
Properties:
FunctionName: 'cost-controller-function'
#!/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
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')