Cập nhật Unicorn Management Service

  1. 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

Working with SNS

  1. 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

Working with SNS

  1. 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)

Working with SNS

  1. 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'])
            }
        }
    )

Working with SNS

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

Working with SNS

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

Working with SNS