|
| 1 | +import boto3 |
| 2 | +from staxapp.config import Config |
| 3 | +from staxapp.openapi import StaxClient |
| 4 | + |
| 5 | +# Requirements |
| 6 | +# - Logged into the deployment bucket account |
| 7 | +# - Logged into the SDK |
| 8 | + |
| 9 | +Config.access_key = <Access Key> |
| 10 | +Config.secret_key = <Secret Key> |
| 11 | + |
| 12 | +# Deployment bucket name |
| 13 | +deployment_bucket_name = <Deployment bucket workload name> |
| 14 | +# Path to Cloudformation file to deploy as a workload |
| 15 | +cloudformation_manifest_path = <Cloudformation File> |
| 16 | +# Catalogue Id |
| 17 | +catalogue_id = <Catalogue Id> |
| 18 | +#The new Catalogue version |
| 19 | +catalogue_version = <Catalogue Version> |
| 20 | + |
| 21 | +workload_client = StaxClient('workloads') |
| 22 | + |
| 23 | +# Get the AWS name of the deployment bucket |
| 24 | +ssm = boto3.client("ssm") |
| 25 | +bucket_name = ssm.get_parameter(Name=f"/workloads/{deployment_bucket_name}/BucketName", WithDecryption=True) |
| 26 | + |
| 27 | +#Upload the cfn to the deployment bucket |
| 28 | +s3 = boto3.resource('s3') |
| 29 | +workload_client = StaxClient("workloads") |
| 30 | +cfn_name = f'{catalogue_version}-{catalogue_name}.yaml' |
| 31 | +s3.Bucket(bucket_name["Parameter"]["Value"]).upload_file(cloudformation_manifest_path, cfn_name) |
| 32 | + |
| 33 | +# Make the cfn into a workload catalogue item |
| 34 | +manifest_body = f"""Resources: |
| 35 | + - WorkloadSSM: |
| 36 | + Type: AWS::Cloudformation |
| 37 | + TemplateURL: s3://{bucket_name["Parameter"]["Value"]}/{cfn_name} |
| 38 | +""" |
| 39 | + |
| 40 | +response = workload_client.CreateCatalogueVersion( |
| 41 | + ManifestBody=manifest_body, |
| 42 | + Version=catalogue_version, |
| 43 | + Description='Updating versions via sdk', |
| 44 | + catalogue_id=catalogue["Id"] |
| 45 | +) |
| 46 | +print(response) |
0 commit comments