Created
October 1, 2019 02:19
-
-
Save armandmcqueen/abd002833f7991c2e66207b2e5b0f1e3 to your computer and use it in GitHub Desktop.
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
import boto3 | |
import time | |
# Manually entered params | |
TEMPLATE_URL = "https://quilt-marketplace.s3.amazonaws.com/releases/test/quilt3.0/c714ae8/default.yaml" | |
STACK_NAME = "staging-canary" | |
AWS_PROFILE = "staging" | |
REGION = "us-east-1" | |
PARAMS = { | |
"AdminUsername": "admin", | |
"AdminEmail": "XXXXXXXXXXXXXX", | |
"AdminPassword": "XXXXXXXXXXXXXXXX", | |
"QuiltBucketName": "staging-canary", | |
"BucketTitle": "Staging Canary", | |
"BucketIcon": "https://d1zvn9rasera71.cloudfront.net/q-128-square.png", | |
"BucketDescription": "Team data hub", | |
"CertificateArnELB": "arn:aws:acm:us-east-1:XXXXXXXXXXXX:certificate/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", | |
"QuiltWebHost": "sub.domain.com", | |
"DBPassword": "XXXXXXXXXXXX", | |
"LicenseKey": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", | |
"CreateDefaultRoles": True, | |
"IdentityProvider": "Quilt", | |
"SingleSignOnDomains": None, | |
"GoogleClientId": None, | |
} | |
def cfn_client(): | |
return boto3.session.Session(profile_name=AWS_PROFILE, region_name=REGION).client('cloudformation') | |
def convert_param_representation(param_dict): | |
param_list = [] | |
for k, v in param_dict.items(): | |
if v is None: | |
v = "" | |
if isinstance(v, bool): | |
v = str(v).lower() | |
param_list.append({ | |
'ParameterKey': k, | |
'ParameterValue': v | |
}) | |
print(param_list) | |
return param_list | |
def deploy_default_stack(): | |
client = cfn_client() | |
parameter_list = convert_param_representation(PARAMS) | |
response = client.create_stack( | |
StackName=STACK_NAME, | |
TemplateURL=TEMPLATE_URL, | |
Parameters=parameter_list, | |
Capabilities=['CAPABILITY_NAMED_IAM'], | |
OnFailure='DO_NOTHING', | |
EnableTerminationProtection=False | |
) | |
return response["StackId"] | |
def describe_stack_status(stack_id): | |
client = cfn_client() | |
response = client.describe_stacks(StackName=stack_id) | |
assert len(response["Stacks"]) == 1, f'Should be exactly one stack with Stack ID: {stack_id}' | |
return response["Stacks"][0] | |
def display_stack_description(stack): | |
""" | |
Stack is a single Stack element from the describe_stacks API call | |
https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cloudformation.html#CloudFormation.Client.describe_stacks | |
""" | |
print(stack["StackName"], stack["StackStatus"], stack.get("StackStatusReason", ""), stack["StackId"]) | |
def delete_test_stack(): | |
# Get CloudTrailBucket and AnalyticsBucket | |
# Empty both so they can be deleted (carefully, so it only works for short-lived canary stacks!) | |
# Delete CFN stack | |
raise NotImplementedError() | |
if __name__ == '__main__': | |
stack_id = deploy_default_stack() | |
print(stack_id) | |
while True: | |
stack_description = describe_stack_status(stack_id) | |
display_stack_description(stack_description) | |
if stack_description["StackStatus"] in ["CREATE_FAILED", "CREATE_COMPLETE"]: | |
break | |
time.sleep(2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment