Update Unicorn Management Service
Update Unicorn Management Service
- First, we grant IAM permission to Lambda.
- Update the SAM template code/lab-1/template.yaml:
- SNSPublishMessagePolicy:
TopicName: !GetAtt RideCompletionTopic.TopicName

- Next, we must grant the Amazon SNS topic ARN to Lambda.
- Continue updating the SAM template code/lab-1/template.yaml:
TOPIC_ARN: !Ref RideCompletionTopic

- Then, we will update the Lambda function to call Amazon SNS.
- Open the file code/lab-1/unicorn-management-service/app.py:
sns = boto3.client('sns', config=config)

- Next, we will put an item into DynamoDB:
response = sns.publish(
TopicArn=TOPIC_ARN,
Message=json.dumps(request),
MessageAttributes = {
'fare': {
'DataType': 'Number',
'StringValue': str(request['fare'])
},
'distance': {
'DataType': 'Number',
'StringValue': str(request['distance'])
}
}
)

- Update the template using the following command:
cd ~/wild-rydes-async-messaging/code/lab-1
sam build --use-container

- After updating, we deploy using the following command:
