-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathaws_env.py
executable file
·74 lines (56 loc) · 2.23 KB
/
aws_env.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/python
import argparse
import json
import sys
import requests
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument("queue_type", choices=["nat", "public"], type=str)
parser.add_argument("app", type=str)
return parser.parse_args()
args = parse_args()
resp = requests.put("http://169.254.169.254/latest/api/token", headers={"X-aws-ec2-metadata-token-ttl-seconds": 21600})
if resp.status_code != 200:
sys.exit(1)
token = resp.text
resp = requests.get(
"http://169.254.169.254/latest/dynamic/instance-identity/document", headers={"X-aws-ec2-metadata-token": token}
)
if resp.status_code != 200:
sys.exit(1)
ident = json.loads(resp.text)
task_queue = "https://sqs.%s.amazonaws.com/%s/%s-task-queue-%s" % (
ident["region"],
ident["accountId"],
args.app,
args.queue_type,
)
priority_task_queue = "https://sqs.%s.amazonaws.com/%s/%s-priority-task-queue-%s" % (
ident["region"],
ident["accountId"],
args.app,
args.queue_type,
)
callback_queue = "https://sqs.%s.amazonaws.com/%s/%s-callback-queue" % (ident["region"], ident["accountId"], args.app)
event_queue = "https://sqs.%s.amazonaws.com/%s/%s-event-queue" % (ident["region"], ident["accountId"], args.app)
ecr = "%s.dkr.ecr.%s.amazonaws.com" % (ident["accountId"], ident["region"])
django_secret_arn = "arn:aws:secretsmanager:%s:%s:secret:%s/django-secret-key" % (
ident["region"],
ident["accountId"],
args.app,
)
db_creds_arn = "arn:aws:secretsmanager:%s:%s:secret:%s/db-user" % (ident["region"], ident["accountId"], args.app)
print("TASK_QUEUE=%s" % task_queue)
print("PRIORITY_TASK_QUEUE=%s" % priority_task_queue)
print("ECR=%s" % ecr)
# HOST_WORKING_DIR is mapped into the engine/plugin docker containers for holding the cloned repo
# print("HOST_WORKING_DIR=/data/artemis/work")
print("HOST_WORKING_DIR=/cloned_repos")
print("INSTANCE_ID=%s" % ident["instanceId"])
print("DEFAULT_DEPTH=500")
print("CALLBACK_QUEUE=%s" % callback_queue)
print("EVENT_QUEUE=%s" % event_queue)
print("ANALYZER_DJANGO_SECRETS_ARN=%s" % django_secret_arn)
print("ANALYZER_DB_CREDS_ARN=%s" % db_creds_arn)
print("S3_BUCKET=%s-%s" % (args.app, ident["accountId"]))
print("LOG_GROUP=/%s/engine/cluster/%s" % (args.app, args.queue_type))