|
36 | 36 | DD_USE_VPC, |
37 | 37 | ) |
38 | 38 |
|
| 39 | +GOV, CN = "gov", "cn" |
| 40 | + |
39 | 41 |
|
40 | 42 | logger = logging.getLogger() |
41 | 43 |
|
@@ -378,6 +380,16 @@ def find_s3_source(key): |
378 | 380 | return "s3" |
379 | 381 |
|
380 | 382 |
|
| 383 | +def get_partition_from_region(region): |
| 384 | + partition = "aws" |
| 385 | + if region: |
| 386 | + if GOV in region: |
| 387 | + partition = "aws-us-gov" |
| 388 | + elif CN in region: |
| 389 | + partition = "aws-cn" |
| 390 | + return partition |
| 391 | + |
| 392 | + |
381 | 393 | def parse_service_arn(source, key, bucket, context): |
382 | 394 | if source == "elb": |
383 | 395 | # For ELB logs we parse the filename to extract parameters in order to rebuild the ARN |
@@ -406,8 +418,9 @@ def parse_service_arn(source, key, bucket, context): |
406 | 418 | elbname = name.replace(".", "/") |
407 | 419 | if len(idsplit) > 1: |
408 | 420 | idvalue = idsplit[1] |
409 | | - return "arn:aws:elasticloadbalancing:{}:{}:loadbalancer/{}".format( |
410 | | - region, idvalue, elbname |
| 421 | + partition = get_partition_from_region(region) |
| 422 | + return "arn:{}:elasticloadbalancing:{}:{}:loadbalancer/{}".format( |
| 423 | + partition, region, idvalue, elbname |
411 | 424 | ) |
412 | 425 | if source == "s3": |
413 | 426 | # For S3 access logs we use the bucket name to rebuild the arn |
@@ -446,8 +459,8 @@ def parse_service_arn(source, key, bucket, context): |
446 | 459 | filesplit = filename.split("_") |
447 | 460 | if len(filesplit) == 6: |
448 | 461 | clustername = filesplit[3] |
449 | | - return "arn:aws:redshift:{}:{}:cluster:{}:".format( |
450 | | - region, accountID, clustername |
| 462 | + return "arn:{}:redshift:{}:{}:cluster:{}:".format( |
| 463 | + get_partition_from_region(region), region, accountID, clustername |
451 | 464 | ) |
452 | 465 | return |
453 | 466 |
|
|
0 commit comments