Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AWS Fargate Cluster with Cloudformation
project:
name: ecs
regions:
- us-east-2
tests:
default:
template: FargateCluster.yaml
parameters:
ECSClusterName: "test-cluster"
import boto3
from botocore.exceptions import ClientError
import re
s3 = boto3.resource('s3')
try:
client = boto3.client('s3')
except ClientError as e:
# Couldn't connect to AWS
print("AWS API couldn't connect. exiting.")
sys.exit(1)
r = re.compile('^tcat.*$')
task_cat_buckets = [b['Name'] for b in client.list_buckets()['Buckets'] if r.match(b['Name'])]
for bucket in task_cat_buckets:
# must first delete contents of bucket before we can delete bucket
s3.Bucket(bucket).objects.all().delete()
s3.Bucket(bucket).delete()
AWSTemplateFormatVersion: '2010-09-09'
Description: 'AWS CloudFormation Template used to create ECS Fargte Cluster.'
Parameters:
ECSClusterName:
AllowedPattern: '[a-zA-Z][a-zA-Z0-9\-]*'
ConstraintDescription: must begin with a letter and contain only alphanumeric
characters, or hyphens.
Default: 'test-cluster'
Description: The ECS cluster name
MaxLength: '64'
MinLength: '1'
Type: String
Resources:
ECSCluster:
Type: 'AWS::ECS::Cluster'
Properties:
ClusterName: !Sub ${ECSClusterName}
CapacityProviders:
- FARGATE
- FARGATE_SPOT
DefaultCapacityProviderStrategy:
- CapacityProvider: FARGATE
Weight: 1
- CapacityProvider: FARGATE_SPOT
Weight: 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment