Now we are ready to configure the subscription for the customer notification service:
After selecting the topic RideCompletionTopic, click the Create subscription button in the bottom right corner.
In the next page, select AWS Lambda as the subscription protocol. In the Endpoint dropdown type CustomerNotification, and select the ARN of the Lambda function.
To look-up the subscription endpoint, navigate back to your CloudFormation console, select the stack wild-rydes-async-msg-1 and select the Outputs tab. Select the value, corresponding to the key CustomerNotificationFunction. It should look similar like
You can also look-up the value by running the following command:
aws cloudformation describe-stacks \ --stack-name wild-rydes-async-msg-1 \ --query 'Stacks.Outputs[?OutputKey==`CustomerNotificationFunction`].OutputValue' \ --output text
Click Create subscription to create the subscription.
Amazon SNS and AWS Lambda are integrated so the subscription is immediately established and the Status will change to Confirmed. There is nothing to do for you in this step.
To validate that the trigger was created for the Lambda function, navigate to the AWS Lambda console. Open the Customer Notification function. In the function overview you should see the SNS service icon. Click on the icon and make sure you have the RideCompletionTopic trigger listed.
In your Cloud9 IDE for this workshop, open the SAM template file ‘wild-rydes-async-messaging/lab-1/template.yaml’. In the Resources section, uncomment the Amazon SNS event source for the CustomerNotificationFunction. You can find the AWS SAM documentation to do so here.
Events: SNSEvent: Type: SNS Properties: Topic: !Ref RideCompletionTopic
Run the following command to build the lab again, after we have added the Amazon SNS subscription:
cd ~/environment/wild-rydes-async-messaging/lab-1 sam build
Now we are ready to update the application, by running the following command to deploy the change:
Note: you do not need to provide the arguments for the deployment, because AWS SAM saved the parameter values in a configuration file called samconfig.toml. See the documentation more information on the AWS SAM CLI configuration file.
Because AWS SAM will only deploy/update/delete resources which are changed, it only takes a couple of seconds to deploy the new Amazon SNS topic.