shafia askari
shafia askari

Reputation: 69

Publish a message to AWS SNS topic on on_failure_callback from DAG

I have a DAG that I have deployed on astro.In the DAG I have on_failure_callback as the default parameter on the dag level and I am calling a method that publishes to the aws sns topic when the dag fail, However, I am getting this error. Has someone ever published a message to aws sns from dag ?

here is my code:

def publish_to_sns(context, "failed"):   
      sns = boto3.client("sns")
       response = sns.publish(
       Message=json.dumps(message),
       TopicArn=f"{ENV_SNS}xxx",
       Subject=subject,
       MessageStructure='json',
       MessageAttributes= attributes
     )
        
    def task_dag_fail_alert(context):
       publish_to_sns(context, "failed")
    
    
      dag = DAG(
                dag_id="xxx",
                default_args={
                    "owner": "airflow",
                    "depends_on_past": False,
                    "retries": 0,
                    "catchup": False,
                    "on_failure_callback":task_dag_fail_alert
                },
                default_view="graph",
                schedule_interval=None,
                start_date=days_ago(1),
                max_active_runs=1
            )
    
    

error:

botocore.errorfactory.AuthorizationErrorException: An error occurred (AuthorizationError) when calling the Publish operation: User: xxx-role/AirflowS3Logs-/botocore-session-is not authorized to perform: SNS:Publish on resource: arn:aws:sns:us-east-2:xxx:xxx because no permissions boundary allows the SNS:Publish action

Upvotes: 0

Views: 313

Answers (0)

Related Questions