Skip to content

Instantly share code, notes, and snippets.

@sk-t3ch
sk-t3ch / Hello_World_API-Lambda.yml
Last active May 5, 2020 19:26
Hello World API CloudFormation - Python Lambda
Lambda:
Type: AWS::Lambda::Function
Properties:
Code:
ZipFile: |
def handler(event, context):
response = {
'isBase64Encoded': False,
'statusCode': 200,
'body': 'HELLO WORLD!'
@sk-t3ch
sk-t3ch / Hello_World_API-ALB.yml
Created May 5, 2020 18:58
Hello World API CloudFormation - Application Load Balancer
LoadBalancerSecGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Load balance allow port 80 traffic
VpcId: !ImportValue VPCID
SecurityGroupIngress:
CidrIp: 0.0.0.0/0
FromPort: 80
IpProtocol: TCP
ToPort: 80
@sk-t3ch
sk-t3ch / Hello_World_API-Lambda_CORS.yml
Last active May 5, 2020 19:25
Hello World API CloudFormation - Python Lambda with CORS enabled
Lambda:
Type: AWS::Lambda::Function
Properties:
Code:
ZipFile: |
def handler(event, context):
response = {
'isBase64Encoded': False,
'statusCode': 200,
'body': 'HELLO WORLD!',
@sk-t3ch
sk-t3ch / Hello_World_Cluster-WebServer.py
Last active May 6, 2020 10:39
Hello World Cluster CloudFormation - Python Web Server with CORS enabled
from aiohttp import web
import aiohttp_cors
import json
async def healthcheck(_):
headers = {
"Cache-Control": "no-cache, no-store, must-revalidate",
"Pragma": "no-cache",
"Expires": "0",
}
@sk-t3ch
sk-t3ch / Hello_World_Cluster-ALB.yml
Created May 6, 2020 10:32
Hello World Cluster CloudFormation - Application Load Balancer
LoadBalancerSecGroup:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Load balancer only allow http port traffic
VpcId: !ImportValue VPCID
SecurityGroupIngress:
CidrIp: 0.0.0.0/0
FromPort: 80
IpProtocol: TCP
ToPort: 80
@sk-t3ch
sk-t3ch / Hello_World_Cluster-Dockerfile
Created May 6, 2020 10:37
Hello World Cluster CloudFormation - Python Web Server Dockerfile
FROM python:3.7-slim
COPY requirements.txt /app/requirements.txt
WORKDIR /app
RUN pip install -r requirements.txt
COPY src /app
EXPOSE 5000
CMD python app.py
@sk-t3ch
sk-t3ch / Hello_World_Cluster-Cluster.yml
Last active October 27, 2020 00:07
Hello World Cluster CloudFormation - ECS Cluster and ECR Repo
ECSCluster:
Type: 'AWS::ECS::Cluster'
Properties:
ClusterName: ECSCluster
CapacityProviders:
- FARGATE_SPOT
DefaultCapacityProviderStrategy:
- CapacityProvider: FARGATE_SPOT
Weight: 1
ClusterSettings:
@sk-t3ch
sk-t3ch / Hello_World_Cluster-Launch_Template.yml
Created May 6, 2020 10:49
Hello World Cluster CloudFormation - Launch Template
LaunchTemplate:
Type: AWS::EC2::LaunchTemplate
Metadata:
AWS::CloudFormation::Init:
config:
packages:
yum:
amazon-ssm-agent: []
commands:
00_amazon_ssm_agent_start:
@sk-t3ch
sk-t3ch / Hello_World_Cluster-ASG_CPU_Policy.yml
Created May 6, 2020 10:57
Hello World Cluster CloudFormation - Auto Scaling Group CPU Scaling Policy
AutoScalingPolicy:
Type: AWS::AutoScaling::ScalingPolicy
Properties:
AutoScalingGroupName: !Ref AutoScalingGroup
PolicyType: TargetTrackingScaling
TargetTrackingConfiguration:
PredefinedMetricSpecification:
PredefinedMetricType: ASGAverageCPUUtilization
TargetValue: 70
@sk-t3ch
sk-t3ch / Hello_World_Cluster-ASG_Spot_Fleet.yml
Created May 6, 2020 10:58
Hello World Cluster CloudFormation - Auto Scaling Group Using Spot Fleet
AutoScalingGroup:
Type: AWS::AutoScaling::AutoScalingGroup
Properties:
MinSize: "1"
MaxSize: "2"
DesiredCapacity: "2"
HealthCheckGracePeriod: 300
MixedInstancesPolicy:
InstancesDistribution:
OnDemandBaseCapacity: 1