Skip to content

Commit a047913

Browse files
committed
Merge branch 'master' into lambda
2 parents f4f301e + 7f83505 commit a047913

File tree

5 files changed

+35
-9
lines changed

5 files changed

+35
-9
lines changed

.ebextensions/env.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
1+
Parameters:
2+
EmailAddress:
3+
Type: String
4+
5+
16
option_settings:
27
aws:elasticbeanstalk:customoption:
38
NotificationEmail: [email protected]
49
aws:elasticbeanstalk:application:environment:
510
AWS_REGION: '`{"Ref" : "AWS::Region"}`'
611
NOTIFICATION_TOPIC: '`{"Ref" : "NotificationTopic"}`'
12+
NOTIFICATION_EMAIL: '`{"Ref" : "EmailAddress"}`'

.ebextensions/sns-topic.config

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ Resources:
33
Type: AWS::SNS::Topic
44
Properties:
55
Subscription:
6-
- Endpoint:
7-
Fn::GetOptionSetting: {DefaultValue: [email protected], OptionName: NotificationEmail}
6+
- Endpoint: {"Ref" : "EmailAddress"}
87
Protocol: email

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,13 +108,13 @@ Deploy the source code for the project to your Elastic Beanstalk environment.
108108
Click through the app to explore its functionality. Use the network console in your browser to see the HTTP requests that it sends to the API to read and write users, sessions, games, moves and game state to DynamoDB via the API.
109109

110110
## Configure Notifications
111-
The API uses Amazon SNS to send a notification email whenever a game ends. Configure your email address in the source code and redeploy to enable notifications.
111+
The API uses Amazon SNS to send a notification email when a game ends. To enable notifications, configure your email address in an environment variable.
112112

113113
*To enable notifications*
114-
1. Clone this repository
115-
2. Add your email address to the `env.config` configuration file in the `.ebextensions` folder.
116-
3. [Create a source bundle](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/applications-sourcebundle.html).
117-
4. [Deploy the source bundle](http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.deploy-existing-version.html#deployments-newversion).
114+
1. Open your environment's page in the [environment management console](https://docs.aws.amazon.com/elasticbeanstalk/latest/dg/environments-console.html).
115+
2. Choose **Configuration**.
116+
3. Choose **Software Configuration**
117+
4. Under **Environment Properties**, set **NOTIFICATION_TOPIC** to your email address.
118118
5. Check your email for a subscription confirmation.
119119
6. Complete a game to trigger a notification.
120120

src/main/java/scorekeep/Utils.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import com.amazonaws.services.sns.AmazonSNSClientBuilder;
66
import com.amazonaws.services.sns.model.PublishRequest;
77
import com.amazonaws.services.sns.model.PublishResult;
8-
8+
import com.amazonaws.services.sns.model.SubscribeRequest;
99
import org.slf4j.Logger;
1010
import org.slf4j.LoggerFactory;
1111

@@ -23,4 +23,15 @@ public static void sendNotification(String subject, String body) {
2323
PublishResult publishResult = snsclient.publish(publishRequest);
2424
logger.info("Email sent: " + publishResult.getMessageId());
2525
}
26+
27+
/*
28+
* Create an SNS subscription.
29+
*/
30+
public static void createSubscription() {
31+
String topicarn = System.getenv("NOTIFICATION_TOPIC");
32+
String emailaddress = System.getenv("NOTIFICATION_EMAIL");
33+
SubscribeRequest subRequest = new SubscribeRequest(topicarn, "email", emailaddress);
34+
snsclient.subscribe(subRequest);
35+
}
36+
2637
}

src/main/java/scorekeep/WebConfig.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,21 @@
33
import org.springframework.context.annotation.Bean;
44
import javax.servlet.Filter;
55

6+
import org.slf4j.Logger;
7+
import org.slf4j.LoggerFactory;
8+
69
@Configuration
710
public class WebConfig {
11+
private static final Logger logger = LoggerFactory.getLogger(WebConfig.class);
812

913
@Bean
1014
public Filter SimpleCORSFilter() {
1115
return new SimpleCORSFilter();
1216
}
13-
}
17+
18+
static {
19+
if ( System.getenv("NOTIFICATION_EMAIL") != null ){
20+
Utils.createSubscription();
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)