forked from aws-samples/mwaa-disaster-recovery
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmwaa
executable file
·55 lines (45 loc) · 2.08 KB
/
mwaa
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
#!/usr/bin/env python3
"""
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"""
import sys
from botocore.config import Config as AwsConfig
from config import Config
from lib.function.airflow_cli_client import AirflowCliClient, AirflowCliCommand
if len(sys.argv) < 3:
print(
"""
Invalid cli command, use: ./mwaa <region> <airflow-command> <sub-command> <resource>
Example 1: ./mwaa primary dags trigger backup_metadata
Example 2: ./mwaa secondary dags trigger restore_metadata
For list of available airflow cli commands, please visit:
https://docs.aws.amazon.com/mwaa/latest/userguide/airflow-cli-command-reference.html#airflow-cli-commands
"""
)
sys.exit(1)
conf = Config()
primary = sys.argv[1].lower().startswith("p")
region = conf.primary_region if primary else conf.secondary_region
env_name = (
conf.primary_mwaa_environment_name
if primary
else conf.secondary_mwaa_environment_name
)
evn_version = conf.mwaa_version
aws_config = AwsConfig(region_name=region)
client = AirflowCliClient(
environment_name=env_name, environment_version=evn_version, config=aws_config
)
command = AirflowCliCommand(command=f'{" ".join(sys.argv[2:])}')
client.execute(command)