#Upload the cfn to the deployment bucket s3 = boto3.resource('s3') s3.Bucket(bucket_name["Parameter"]["Value"]).upload_file(cloudformation_manifest_path, cfn_name) # Make the cfn into a workload catalogue item manifest_body = f"""Resources: - WorkloadSSM: Type: AWS::Cloudformation TemplateURL: s3://{bucket_name["Parameter"]["Value"]}/{cfn_name} """ catalogue_response = workload_client.CreateCatalogueItem( Name=catalogue_name, ManifestBody=manifest_body, Version=catalogue_version, Description='Allows accounts to access specific api-tokens', Tags={"Test": "creation"} ) # Create a client for tasks task_client = StaxClient("tasks") # Wait until status has finished runnig task={'Status':'RUNNING'} while task.get('Status') == 'RUNNING': time.sleep(2) task = task_client.ReadTask(task_id=catalogue_response['TaskId']) # If the catalogue version succeeded if task.get('Status') == 'SUCCEEDED':
# Catalogue Name catalogue_name = <Catalogue Name> # Catalogue version catalogue_version = <Catalogue Version> # Get the AWS name of the deployment bucket ssm = boto3.client("ssm") bucket_name = ssm.get_parameter(Name=f"/workloads/{deployment_bucket_name}/BucketName", WithDecryption=True) #Upload the cfn to the deployment bucket s3 = boto3.resource('s3') cfn_name = f'{catalogue_version}-{catalogue_name}.yaml' s3.Bucket(bucket_name["Parameter"]["Value"]).upload_file(cloudformation_manifest_path, cfn_name) ## Invoke the Stax SDK workload_client = StaxClient("workloads") # Make the cfn into a workload catalogue item manifest_body = f"""Resources: - WorkloadSSM: Type: AWS::Cloudformation TemplateURL: s3://{bucket_name["Parameter"]["Value"]}/{cfn_name} """ response = workload_client.CreateCatalogueItem( Name=catalogue_name, ManifestBody=manifest_body, Version=catalogue_version, Description='Example of how to use the sdk', )