Skip to content

Commit 9b624a2

Browse files
adding cli command to print information about the service
1 parent b0e9b72 commit 9b624a2

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

stac_updater/cli.py

+36-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import re
33
import shutil
44
import subprocess
5+
import json
56

67
import click
78
import yaml
@@ -149,9 +150,42 @@ def add_logging(es_host):
149150
with open(sls_config_path, 'w') as outf:
150151
yaml.dump(sls_config, outf, indent=1)
151152

152-
@stac_updater.command(name='deploy', short_help="deploy service to aws")
153+
@stac_updater.command(name='deploy', short_help="deploy service to aws.")
153154
def deploy():
154155
subprocess.call("docker build . -t stac-updater:latest", shell=True)
155156
subprocess.call("docker run --rm -v $PWD:/home/stac_updater -it stac-updater:latest package-service.sh", shell=True)
156157
subprocess.call("npm install serverless-pseudo-parameters", shell=True)
157-
subprocess.call("sls deploy -v", shell=True)
158+
subprocess.call("sls deploy -v", shell=True)
159+
160+
@stac_updater.command(name='info', short_help="prints information about your service.")
161+
def info():
162+
info = {}
163+
with open(sls_config_path, 'r') as f:
164+
sls_config = yaml.unsafe_load(f)
165+
static_updaters = [sls_config['functions'][x] for x in sls_config['functions'] if x.endswith('update_collection')]
166+
if len(static_updaters) > 0:
167+
info.update({
168+
'static_collections': [{
169+
'root': x['environment']['COLLECTION_ROOT'],
170+
'path': x['environment']['PATH'],
171+
'filename': x['environment']['FILENAME'],
172+
'eventSource': list(x['events'])[0]
173+
} for x in static_updaters]
174+
})
175+
176+
if notification_topic_name in sls_config['resources']['Resources']:
177+
info.update({
178+
'notifications': {
179+
'topicArn': 'arn:aws:sns:#{AWS::Region}:#{AWS::AccountId}:' + notification_topic_name
180+
}
181+
})
182+
183+
if 'es_log_ingest' in sls_config['functions']:
184+
info.update({
185+
'logging': {
186+
'host': sls_config['functions']['es_log_ingest']['environment']['ES_HOST'],
187+
'logGroups': [x['cloudwatchLog']['logGroup'] for x in sls_config['functions']['es_log_ingest']['events']]
188+
}
189+
})
190+
191+
print(json.dumps(info, indent=1))

0 commit comments

Comments
 (0)