Amazon Simple Email Service(Amazon SES)를 Simple Mail Transfer Protocol(SMTP) 호스트로 사용하여 Amazon Managed Workflows for Apache Airflow(Amazon MWAA)의 Directed Acyclic Graph(DAG) 작업에서 이메일을 전송하려고 합니다.
해결 방법
참고: AWS Command Line Interface(AWS CLI) 명령을 실행할 때 오류가 발생하면 AWS CLI의 오류 해결을 참조하십시오. 또한 최신 AWS CLI 버전을 사용하고 있는지 확인하십시오.
Amazon SES를 SMTP 호스트로 사용하여 Amazon MWAA의 DAG 작업에서 이메일을 전송하려면 다음 단계를 완료하십시오.
- Amazon SES를 사용하여 이메일 전송을 설정합니다.
- Amazon SES SMTP 자격 증명을 만들어 Amazon MWAA에서 이메일을 보냅니다.
참고: SMTP 인터페이스 자격 증명은 SMTP 사용자에 대해 AWS Identity Access and Management(IAM)로 만든 액세스 키와는 다릅니다.
- Apache Airflow 구성 옵션을 Amazon MWAA 환경에 연결합니다.
- 구성 옵션에 대해 다음 값을 설정합니다.
email.email_backend를 airflow.utils.email.send_email_smtp로 설정합니다.
smtp.smtp_host를 email-smtp.region.amazonaws.com으로 설정합니다.
참고: region을 AWS 리전으로 바꿉니다.
smtp.smtp_starttls를 True로 설정합니다.
smtp.smtp_ssl을 False로 설정합니다.
smtp.smtp_port를 587로 설정합니다.
참고: SMTP 트래픽에는 포트 587을 사용합니다. 기본적으로 AWS는 모든 Amazon Elastic Compute Cloud(Amazon EC2) 인스턴스의 포트 25에서 아웃바운드 SMTP 트래픽을 차단합니다. 포트 25에서 아웃바운드 트래픽을 전송하려면 제한 해제 요청을 제출하십시오.
smtp.smtp_mail_from을 이메일 주소로 설정합니다.
참고: 위의 구성 옵션에 대한 자세한 내용은 Apache Airflow 웹 사이트에서 [email] 및 [smtp]를 참조하십시오.
- SMTP 사용자 및 암호에 대해 각각 AWS Secrets Manager 보안 암호를 만듭니다. 2번 단계의 Amazon SES SMTP 자격 증명을 사용합니다. 그런 다음, 시작 스크립트를 구성하여 환경 변수를 설정합니다.
참고: SMTP 자격 증명을 Secrets Manager에 저장하는 것이 모범 사례입니다.
- 다음 startup.sh 스크립트를 Amazon Simple Storage Service(Amazon S3) 버킷에 추가합니다.
#!/bin/sh
# Get the SMTP username and password from secrets manager
username=$(aws secretsmanager get-secret-value --secret-id airflow/variables/smtp.smtp_user --query SecretString --output text)
password=$(aws secretsmanager get-secret-value --secret-id airflow/variables/smtp.smtp_password --query SecretString --output text)
# Set the SMTP Environment variables with the username and password retrieved from Secrets Manager
export AIRFLOW__SMTP__SMTP_USER=$username
export AIRFLOW__SMTP__SMTP_PASSWORD=$password
# Print the SMTP user
echo "SMTP user is $AIRFLOW__SMTP__SMTP_USER"
참고: Amazon MWAA 실행 역할에는 개별 보안 암호 값을 검색할 권한이 있어야 합니다.
- 이메일 구성 옵션과 시작 스크립트의 Amazon S3 경로를 사용하여 Amazon MWAA 환경을 업데이트하려면 다음 update-environment AWS CLI 명령을 실행합니다.
aws mwaa update-environment --name environment_name --startup-script-s3-path s3_path_for_startup_script
참고: environment_name을 환경 이름으로 바꾸고 s3_path_for_startup_script를 시작 스크립트의 S3 경로로 바꿉니다.
환경을 만들거나 업데이트하는 경우 성공, 실패 및 재시도에 대한 Apache Airflow 콜백은 위 구성을 사용합니다. EmailOperator와 함께 작업을 사용하여 이메일을 보낼 수도 있습니다. 자세한 내용은 Apache Airflow 웹 사이트의 airflow.providers.smtp.operators.smtp를 참조하십시오.