Skip to content

Commit

Permalink
IPublisher methods for accessing env vars
Browse files Browse the repository at this point in the history
  • Loading branch information
upparekh committed Sep 1, 2021
1 parent 8564fdf commit 25a6359
Showing 1 changed file with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import { Construct } from '@aws-cdk/core';
*/
export interface IPublisher {
publish(taskDefinition: ecs.TaskDefinition): void;

envVarKey(): string;

envVarValue(): string;
}

/**
Expand Down Expand Up @@ -60,6 +64,14 @@ export class PublisherTopic implements IPublisher {
public publish(taskDefinition: ecs.TaskDefinition) {
this.topic.grantPublish(taskDefinition.taskRole);
}

public envVarKey(): string {
return this.topic.node.id;
}

public envVarValue(): string {
return this.topic.topicArn;
}
}

/**
Expand Down Expand Up @@ -124,9 +136,7 @@ export class PublisherExtension extends ServiceExtension {
this.parentService = service;

for (const resource of this.props.publishers) {
if (resource instanceof PublisherTopic) {
this.environment[`${service.id.toUpperCase()}_${resource.topic.node.id.toUpperCase()}_ARN`] = resource.topic.topicArn;
}
this.environment[`${service.id.toUpperCase()}_${resource.envVarKey().toUpperCase()}_ARN`] = resource.envVarValue();
}
}

Expand Down

0 comments on commit 25a6359

Please sign in to comment.