Created
April 21, 2022 07:31
-
-
Save learn2skills/1ac22ef77fc606855b03b3457ece0547 to your computer and use it in GitHub Desktop.
AWS Fargate Cluster with Cloudformation
This file contains 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
project: | |
name: ecs | |
regions: | |
- us-east-2 | |
tests: | |
default: | |
template: FargateCluster.yaml | |
parameters: | |
ECSClusterName: "test-cluster" |
This file contains 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
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() |
This file contains 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' | |
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