Cập nhật Unicorn Management Service
- Trước hết chúng ta cấp quyền IAM cho Lambda
- Cập nhật SAM template code/lab-1/template.yaml
- SNSPublishMessagePolicy:
TopicName: !GetAtt RideCompletionTopic.TopicName

- Tiếp theo chúng ta phải cấp Amazon SNS topic ARN cho Lambda.
- Tiếp tục cập nhật SAM template code/lab-1/template.yaml
TOPIC_ARN: !Ref RideCompletionTopic

- Sau đó, chúng ta sẽ cập nhật Lambda function để gọi đến Amazon SNS
- Mở file code/lab-1/unicorn-management-service/app.py
sns = boto3.client('sns', config=config)

- Tiếp đến, chúng ta sẽ put item vào 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'])
}
}
)

- Cập nhật template bằng lệnh sau:
cd ~/wild-rydes-async-messaging/code/lab-1
sam build --use-container

- Sau khi cập nhật, chúng ta triển khai bằng lệnh sau:
sam deploy
