1. VPC Reachability Analyzer 경로를 생성합니다.

2. 출발지 소스를 지정합니다.

3. 대상으로 지정합니다.

4. Amazon Simple Notification Service(Amazon SNS)

5. AWS Lambda 함수를 생성하여 Reachability Analyzer를 시작하고 분석이 실패할 경우 SNS 주제에 메시지를 게시합니다.

6. Lambda 함수를 호출하는 Amazon EventBridge(Amazon CloudWatch Events) 규칙을 생성합니다.

-> EventBridge 를 Cron 으로 설정하여 주기적으로 Lambda 를 실행하게 설정

 

 

 

[참고 코드]

import boto3

def lambda_handler(event, context):
    aws_region = 'your_aws_region'

    instance_id = 'your_instance_id'
    service_id = 'your_service_id'

    sns_topic_arn = 'your_sns_topic_arn'

    client = boto3.client('networkmanager', region_name=aws_region)

    try:
        # Reachability Analyzer 실행
        response = client.create_connectivity_test(
            GlobalNetworkId=service_id,
            TestDescription='Reachability Analyzer Test',
            ResourceType='EC2_INSTANCE',
            Source={
                'Ec2InstanceId': instance_id
            }
        )

        # Reachability Analyzer 실행 결과 반환
        test_id = response['ConnectivityTest']['ConnectivityTestId']
        return {
            'statusCode': 200,
            'body': f'Reachability Analyzer test started. Test ID: {test_id}'
        }
    except Exception as e:
        # Reachability Analyzer 실행 실패 시 SNS 알림 발생
        sns_client = boto3.client('sns', region_name=aws_region)
        sns_client.publish(
            TopicArn=sns_topic_arn,
            Message=f'Reachability Analyzer test failed: {str(e)}'
        )
        return {
            'statusCode': 500,
            'body': f'Reachability Analyzer test failed. Error: {str(e)}'
        }

'AWS' 카테고리의 다른 글

AWS Route53 DNA Type  (0) 2023.07.22
AWS Gateway Endpoint  (0) 2023.07.21
AWS 특정 VPC, IP S3 버킷 허용 하는 방법  (0) 2023.07.11
AWS EC2 Instance Metadata(IMDS)  (0) 2023.07.10
AWS EKS SVC 로 NLB 사용 시 Time out 발생 현상  (1) 2023.07.09

+ Recent posts