AWSScriptBehaviorDynamoDB.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <AzCore/EBus/EBus.h>
  10. #include <AzCore/std/string/string.h>
  11. namespace AWSCore
  12. {
  13. using DynamoDBAttributeValueMap = AZStd::unordered_map<AZStd::string, AZStd::string>;
  14. //! AWS Script Behavior notifications for ScriptCanvas behaviors that interact with AWS DynamoDB
  15. class AWSScriptBehaviorDynamoDBNotifications
  16. : public AZ::EBusTraits
  17. {
  18. public:
  19. ///////////////////////////////////////////////////////////////////////////////////
  20. // EBusTraits overrides
  21. static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple;
  22. static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
  23. //! Called when a successful script behavior dynamodb get item call has occurred
  24. virtual void OnGetItemSuccess(const DynamoDBAttributeValueMap& resultBody) = 0;
  25. //! Called when script behavior dynamodb get item call has failed
  26. virtual void OnGetItemError(const AZStd::string& errorBody) = 0;
  27. };
  28. using AWSScriptBehaviorDynamoDBNotificationBus = AZ::EBus<AWSScriptBehaviorDynamoDBNotifications>;
  29. class AWSScriptBehaviorDynamoDBNotificationBusHandler
  30. : public AWSScriptBehaviorDynamoDBNotificationBus::Handler
  31. , public AZ::BehaviorEBusHandler
  32. {
  33. public:
  34. AZ_EBUS_BEHAVIOR_BINDER(
  35. AWSScriptBehaviorDynamoDBNotificationBusHandler, "{476BEB41-5C5E-4C18-9801-170309E658BE}",
  36. AZ::SystemAllocator, OnGetItemSuccess, OnGetItemError);
  37. void OnGetItemSuccess(const DynamoDBAttributeValueMap& resultBody) override
  38. {
  39. Call(FN_OnGetItemSuccess, resultBody);
  40. }
  41. void OnGetItemError(const AZStd::string& errorBody) override
  42. {
  43. Call(FN_OnGetItemError, errorBody);
  44. }
  45. };
  46. class AWSScriptBehaviorDynamoDB
  47. {
  48. public:
  49. AZ_RTTI(AWSScriptBehaviorDynamoDB, "{569E74F6-1268-4199-9653-A3B603FC9F4F}");
  50. AWSScriptBehaviorDynamoDB() = default;
  51. virtual ~AWSScriptBehaviorDynamoDB() = default;
  52. static void Reflect(AZ::ReflectContext* context);
  53. static void GetItem(const AZStd::string& tableResourceKey, const DynamoDBAttributeValueMap& keyMap);
  54. static void GetItemRaw(const AZStd::string& table, const DynamoDBAttributeValueMap& keyMap, const AZStd::string& region);
  55. private:
  56. static bool ValidateGetItemRequest(
  57. const AZStd::string& table, const DynamoDBAttributeValueMap& keyMap, const AZStd::string& region);
  58. };
  59. } // namespace AWSCore