Skip to content

Commit

Permalink
Tools - Testing: Removing hardcoded ENV in favor of config (#5610)
Browse files Browse the repository at this point in the history
  • Loading branch information
ford-at-aws authored Nov 2, 2023
1 parent 9465b36 commit 124263a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 14 deletions.
1 change: 1 addition & 0 deletions .tools/test/config/resources.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
topic_name: "aws-weathertop-central-sns-fanout-topic"
bucket_name: "aws-weathertop-central-log-bucket"
admin_acct: "808326389482"
12 changes: 0 additions & 12 deletions .tools/test/sqs_lambda_to_batch_fargate/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,6 @@ For example, if your language is Java, use:
```
export LANGUAGE_NAME=javav2
```

Also, save the AWS account ID of the AWS account that is currently emitting
events for this stack to process.
```
export PRODUCER_ACCOUNT_ID=12345678901
```

Lastly, save the name of the SNS topic that will be producing the previously mentioned events.
If created using [this Producer CDK code](../eventbridge_rule_with_sns_fanout/README.md), it will look something like this:
```
export FANOUT_TOPIC_NAME=ProducerStack-fanouttopic6EFF7954-pYvxBdNPbEWM
```
---

## AWS CDK setup and deployment
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

# Raises KeyError if environment variable doesn't exist.
language_name = os.environ["LANGUAGE_NAME"]
producer_account_id = os.environ["PRODUCER_ACCOUNT_ID"]


class ConsumerStack(Stack):
Expand All @@ -30,6 +29,7 @@ def __init__(self, scope: Construct, id: str, **kwargs) -> None:
resource_config = self.get_yaml_config("../config/resources.yaml")
topic_name = resource_config["topic_name"]
producer_bucket_name = resource_config["bucket_name"]
self.producer_account_id = resource_config["admin_acct"]
sns_topic = self.init_get_topic(topic_name)
sqs_queue = sqs.Queue(self, f"BatchJobQueue-{language_name}")
self.init_subscribe_sns(sqs_queue, sns_topic)
Expand Down Expand Up @@ -143,7 +143,7 @@ def init_subscribe_sns(self, sqs_queue, sns_topic):
statement = iam.PolicyStatement()
statement.add_resources(sqs_queue.queue_arn)
statement.add_actions("sqs:*")
statement.add_arn_principal(f"arn:aws:iam::{producer_account_id}:root")
statement.add_arn_principal(f"arn:aws:iam::{self.producer_account_id}:root")
statement.add_arn_principal(f"arn:aws:iam::{Aws.ACCOUNT_ID}:root")
statement.add_condition("ArnLike", {"aws:SourceArn": sns_topic.topic_arn})
sqs_queue.add_to_resource_policy(statement)
Expand Down

0 comments on commit 124263a

Please sign in to comment.