'How to import airflow variables in MWAA airflow

I'm not able to import new airflow variables from a json file to my MWAA env through Boto3 & aws_mwaa. The response code from aws_mwaa/cli is 400. However, I'm able to get the values of the existing variables though. Any help please?

    import requests
    import boto3
    import base64
   
    
    def main():
        env = "<MWAA-ENV-NAME>"
        client = boto3.client('mwaa')
        response = client.create_cli_token(Name=env)
        auth_token=response.get('CliToken')
        hed = {'Content-Type': 'text/plain', 'Authorization': 'Bearer ' + auth_token}
        data = "variables -i <local JSON File Path>"
        url = 'https://{web_server}/aws_mwaa/cli'.format(web_server=response.get('WebServerHostname'))
        r = requests.post(url, data=data, headers=hed)
        print_output(r)
    
    
    def print_output(r):
        output = base64.b64decode(r.json()['stdout']).decode('utf8')
        print(output)
    
    
    if __name__ == '__main__':
        main()


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source