Skip to content

nikola-mladenovic/notification-service-aws-lambda

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AWS Lambda Notification Service Example for Sunrise iOS App

Sunrise iOS app push notifications are triggered using Commercetools subscriptions. One of the possible destinations for a subscription is an AWS SNS topic. Messages published to a topic can trigger lambda functions if subscribed. This example will show you how you can easily get notifications to your mobile shop app running on Commercetools platform, without a need for a server instance. The scope of this example covers reservation notification scenario, triggered on OrderCreated message.

Setup

Credentials

In order to use this example you need:

  • An active Commercetools project. Replace PROJECT_KEY, SCOPE, CLIENT_ID, CLIENT_SECRET, API_URL and AUTH_URL with values valid for your project.
  • AWS access key. Replace AWS_ACCESS_KEY, and AWS_SECRET_KEY with your key and secret.

Create a Topic

  • Navigate to the SNS section of the AWS console.
  • Create new topic, copy the ARN and use it to subscribe to OrderCreated message.
  • Now navigate to Applications section, and create new platform application. For the push notification platform, you should select Apple production or Apple development depending on your current app environment. Either upload the certificate file, or paste the certificate and private key into the popup and confirm to save.
  • Copy the ARN you got for the newly created application, and set that value in NotificationUtil.groovy, line platformEndpointRequest.setPlatformApplicationArn("arn:aws:sns:us-west-2:487164526243:app/APNS/Sunrise").

Build a JAR file

  • Run gradle fatJar to build a JAR file which contains all dependencies used in the NotificationUtil.groovy script.
    • Optionally, you can use gradle runScript command to run the script locally for debugging purposes.

Add New Lambda Function

  • Navigate to the Lambda section of the AWS console.
  • Create new Lambda function, and use configure function section to set the following values:
    • Configure runtime to Java 8;
    • Function package should contain the JAR file created in the previous step;
    • Handler should be set to de.commercetools.NotificationService::handleRequest if you haven't changed the package name;
    • Configure triggers section allow you to specify a trigger which will invoke your Lambda function. You should select SNS from the dropdown menu, and pick the topic created in the second step.

Test

  • Login with a valid customer account on your Sunrise app instance, and make sure to allow push notifications. Customer's push token will be stored in a Customer's custom field.
  • Pick some product and make a reservation.
  • The Commercetools platform sends an OrderCreated message to the SNS you subscribed. The topic triggers the Lambda function, which retrieves customer's token from the Commercetools API, and passes it, along with the notification payload to the APNS platform application.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages