This repository has been archived by the owner on Jul 22, 2020. It is now read-only.
/
report_s3.py
48 lines (35 loc) · 1.65 KB
/
report_s3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/env python3
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: MIT-0
import json
import sys
def main():
manifest = json.load(open("cdk.out/manifest.json"))
bucket = sys.argv[1]
asset_id = []
asset_key = []
asset_bucket_param = []
for asset in manifest['artifacts']['pcluster']['metadata']['/pcluster']:
asset_id.append(asset['data']['id'])
path = asset['data']['path']
asset_bucket_param.append(asset['data']['s3BucketParameter'])
asset_key.append("placeholder")
if asset['data']['packaging'] == "zip":
# For directories
print("cd cdk.out/{p}; zip -r ../{i}.zip *; cd ../..".
format(p=path, i=asset_id[-1]))
print("aws s3 cp --acl public-read cdk.out/{i}.zip s3://{b}/asset/".
format(p=path, b=bucket, i=asset_id[-1]))
asset_key[-1] = ".".join([asset_id[-1], "zip"])
asset_key[-1] = "/".join(["asset", asset_key[-1]])
elif asset['data']['packaging'] == "file":
# For single files
print("aws s3 cp --acl public-read cdk.out/{p} s3://{b}/{k}".
format(p=path, b=bucket, k=path.replace(".", "/", 1)))
asset_key[-1] = path.replace(".", "/", 1)
else:
print("Unknown packaging format {}".format(asset['data']['packaging']))
print("declare -a asset_id; asset_id=({})".format(" ".join(asset_id)))
print("declare -a asset_key; asset_key=({})".format(" ".join(asset_key)))
print("declare -a asset_bucket_param; asset_bucket_param=({})".format(" ".join(asset_bucket_param)))
main()