AWS Glue Python Shell中获取外网ip

问题

想要确定AWS Glue任务出站流量的外网ip是不是自己配置的vpc外网nat网关ip。

Python

python 复制代码
import urllib.request
import logging

# 初始化日志
logger = logging.getLogger()
logger.setLevel(logging.INFO)

def check_outbound_ip():
    try:
        # 使用 checkip.amazonaws.com 获取外网 IP
        url = "https://checkip.amazonaws.com"
        with urllib.request.urlopen(url, timeout=10) as response:
            external_ip = response.read().decode('utf-8').strip()
            logger.info(f"--- Glue Job Outbound IP: {external_ip} ---")
            return external_ip
    except Exception as e:
        logger.error(f"Failed to fetch outbound IP: {str(e)}")
        return None

# 在 Job 逻辑开始前调用
current_ip = check_outbound_ip()
相关推荐
傻啦嘿哟19 小时前
某短视频平台视频爬虫实战:抓取推荐流视频信息,绕过反爬的3种技巧
开发语言·爬虫·python
迷迭香yy20 小时前
集合竞价数据挖掘实战:用Python构建开盘信号识别系统
人工智能·python·数据挖掘
李昊哲小课1 天前
fastapi sse websocket 奶茶店实时订单看板
人工智能·python·websocket·网络协议·fastapi·sse
2401_844582951 天前
工具包:软件架构设计的实用技巧与经验分享
python
故乡dee云1 天前
AWS CloudFront 使用教程:CDN 加速功能和网站部署优化
云计算·aws
RFID固定资产管理系统1 天前
适配媒体行业的固定资产管理软件有哪些功能与核心优势
大数据·人工智能·python·媒体
SunnyDays10111 天前
Python 为 PowerPoint 添加动画:进入、退出、动作路径与文本动画(详解)
python·powerpoint·动画·动画效果·文本动画
难以怀瑾1 天前
pytest.param`与 allure.dynamic.title()全解析
python
月光船幽幽1 天前
Pytest配置实战:高效管理测试标记与覆盖
python·科技
leoZ2311 天前
实战复盘:用 Claude Code 从零搭一个 GitHub PR 统计工具
java·人工智能·python·深度学习·自然语言处理·github·llama