amazon-web-services - 为创建 ELB 规则而在 boto3 中传递的实际值是多少
问题描述
我正在研究一个用例,其中用户试图在 aws 中创建服务,该服务将从弹性负载均衡器中获取服务。负载均衡器已经存在,但我想使用 boto3 创建/更新规则方法为 ELBv2 创建新规则。该文档包含有关架构级别的信息。但我不确定在哪里编辑 json 中的有效规则。
Conditions=[
{
'Field': 'string',
'Values': [
'string',
],
'HostHeaderConfig': {
'Values': [
'string',
]
},
'PathPatternConfig': {
'Values': [
'string',
]
}]
如果负载均衡器具有 url:example.com - 我想将规则创建为“XYZ”,我可以在上面的字典中传递这些 XYZ。因此,如果我尝试访问example.com/XYZ,该 url 应该可以工作。
解决方案
client = boto3.client('elbv2')
listener_arn = 'listener ARN'
response = client.describe_rules(ListenerArn=listener_arn)
is_rule_exists = False
for rule in response['Rules']:
conditions = rule['Conditions']
for condition in conditions:
for value in condition['Values']:
if value == 'file_pattern_you_want_to_choose':
is_rule_exists = True
else:
print("Nope")
condition = [
{
'Field': 'path-pattern',
'Values': [
'path pattern value',
]
}
]
actions = [{
'Type': 'forward',
'TargetGroupArn': 'target group arn for your instance'
}]
priority = 10
if is_rule_exists:
print('Do Nothing. Or Else create the rule')
client.modify_rule(ListenerArn=listener_arn, conditions=condition, actions=actions)
else:
print('Create the rule')
client.create_rule(ListenerArn=listener_arn, Conditions=condition, Actions=actions, Priority=priority)
以上是python代码片段,我用来获取文件路径模式并检查规则是否存在。如果没有,它将创建规则。否则,您可以修改规则。
推荐阅读
- python - 数据框中的 Pandas FIFO
- snowflake-cloud-data-platform - Snowpipe 收到 S3 消息但不转发
- react-native - 崩溃后React-native redux导航状态重置
- python - 如何在 __init__.py 中动态创建类
- html - 有没有办法让左标签从对象的右侧开始计数?
- c# - c#如何创建循环直到满足条件?
- android - Viewpager 仅更新当前可见片段
- vb.net - 带盖子的组合框自定义控件
- c# - 是否可以在不更改工具提示行为的情况下动态更改 C# 中的工具提示文本?
- r - R 有没有一种简单的方法可以将表格从 R 复制粘贴到电子邮件/单词/谷歌文档?