3
0

AWSScriptBehaviorLambda.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. //! AWS Script Behavior notifications for ScriptCanvas behaviors that interact with AWS Lambda
  14. class AWSScriptBehaviorLambdaNotifications
  15. : public AZ::EBusTraits
  16. {
  17. public:
  18. ///////////////////////////////////////////////////////////////////////////////////
  19. // EBusTraits overrides
  20. static const AZ::EBusHandlerPolicy HandlerPolicy = AZ::EBusHandlerPolicy::Multiple;
  21. static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::Single;
  22. //! Called when a successful script behavior lambda invoke call has occurred
  23. virtual void OnInvokeSuccess(const AZStd::string& resultBody) = 0;
  24. //! Called when script behavior lambda invoke call has failed
  25. virtual void OnInvokeError(const AZStd::string& errorBody) = 0;
  26. };
  27. using AWSScriptBehaviorLambdaNotificationBus = AZ::EBus<AWSScriptBehaviorLambdaNotifications>;
  28. class AWSScriptBehaviorLambdaNotificationBusHandler
  29. : public AWSScriptBehaviorLambdaNotificationBus::Handler
  30. , public AZ::BehaviorEBusHandler
  31. {
  32. public:
  33. AZ_EBUS_BEHAVIOR_BINDER(AWSScriptBehaviorLambdaNotificationBusHandler, "{533E8AC9-CBD7-4718-9FBB-622C5E70045F}",
  34. AZ::SystemAllocator, OnInvokeSuccess, OnInvokeError);
  35. void OnInvokeSuccess(const AZStd::string& resultBody) override
  36. {
  37. Call(FN_OnInvokeSuccess, resultBody);
  38. }
  39. void OnInvokeError(const AZStd::string& errorBody) override
  40. {
  41. Call(FN_OnInvokeError, errorBody);
  42. }
  43. };
  44. class AWSScriptBehaviorLambda
  45. {
  46. public:
  47. AZ_RTTI(AWSScriptBehaviorLambda, "{9E71534D-34B3-4723-B180-2552513DDA3D}");
  48. AWSScriptBehaviorLambda() = default;
  49. virtual ~AWSScriptBehaviorLambda() = default;
  50. static void Reflect(AZ::ReflectContext* context);
  51. static void Invoke(const AZStd::string& functionResourceKey, const AZStd::string& payload);
  52. static void InvokeRaw(const AZStd::string& functionName, const AZStd::string& payload, const AZStd::string& region);
  53. private:
  54. static bool ValidateInvokeRequest(const AZStd::string& functionName, const AZStd::string& region);
  55. };
  56. } // namespace AWSCore