[{"data":1,"prerenderedAt":81},["ShallowReactive",2],{"content-guides-refactoring-serverless-service_integration":3},{"markdown":4,"frontMatterAttributes":5,"bodyRaw":7,"contributorPaths":8,"menuType":12,"contentName":13,"slug":14,"readingTime":15,"menu":16,"nextDocItem":58,"previousDocItem":50},"\u003Ch2>Description\u003C\u002Fh2>\n\u003Cp>As part of your AWS Step Functions workflow, if you want to integrate with other AWS Services like Amazon Rekognition to detect object in an image, run and wait for AWS Batch job, or run an Amazon Elastic Container Service (Amazon ECS) task and wait for it to complete, you had to write a custom AWS Lambda function to handle each step of that service integration.\u003C\u002Fp>\n\u003Cp>An example of custom Lambda making Rekognition call might look as follows:\u003C\u002Fp>\n\u003Cpre>\u003Ccode class=\"language-js\">const aws = require(&#39;aws-sdk&#39;);\nconst rekognition = new aws.Rekognition();\n\nexports.handler = async (event,context, callback) =&gt; {\n    ...\n    result = await rekognition.detectLabels(params).promise();\n    ...\n}\n\u003C\u002Fcode>\u003C\u002Fpre>\n\u003Cp>\u003Cimg src=\"\u002Fassets\u002Fexternal\u002Fguides\u002Frefactoring-serverless\u002Fassets\u002Fimages\u002Fservice_integration_original.png\" alt=\"\">  \u003C\u002Fp>\n\u003Ch2>Solution\u003C\u002Fh2>\n\u003Cp>Use Step Functions&#39; \u003Ca href=\"https:\u002F\u002Fdocs.aws.amazon.com\u002Fstep-functions\u002Flatest\u002Fdg\u002Fsupported-services-awssdk.html\">SDK Service Integration\u003C\u002Fa> to directly call each AWS Service&#39;s API directly from your worklow.\u003C\u002Fp>\n\u003Cp>\u003Cimg src=\"\u002Fassets\u002Fexternal\u002Fguides\u002Frefactoring-serverless\u002Fassets\u002Fimages\u002Fservice_integration_refactored.png\" alt=\"\">\u003C\u002Fp>\n\u003Cp>See the CDK implementation of this pattern in Typescript on \u003Ca href=\"https:\u002F\u002Fgithub.com\u002Faws-samples\u002Faws-refactoring-to-serverless\u002Fblob\u002Fmain\u002Fimplementation\u002Fservice_integration\u002FREADME.md\">GitHub\u003C\u002Fa>.\u003C\u002Fp>\n\u003Ch2>Considerations\u003C\u002Fh2>\n\u003Ch4>Advantages\u003C\u002Fh4>\n\u003Cul>\n\u003Cli>You eliminate a run-time element (AWS Lambda) and thus reduce cost and run-time complexity.\u003C\u002Fli>\n\u003Cli>You reduce a little latency by eliminating the extra service hop.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Ch4>Limitation\u003C\u002Fh4>\n\u003Cul>\n\u003Cli>You might lose the ability to decouple the API syntax from Step Functions, e.g. by setting defaults or post-processing results in the Lambda function.\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Ch3>Applicability\u003C\u002Fh3>\n\u003Cul>\n\u003Cli>Service Integration can invoke almost all AWS SDK APIs. See \u003Ca href=\"https:\u002F\u002Fdocs.aws.amazon.com\u002Fstep-functions\u002Flatest\u002Fdg\u002Fsupported-services-awssdk.html#unsupported-api-actions-list\">the documentation\u003C\u002Fa> for limitations \u003C\u002Fli>\n\u003Cli>Cost: If you can replace the Lambda invocation with a single Step Functions state, the Step Functions cost remains but you save the Lambda execution cost. if you require an additional step, e.g. a pass state, standard workflows cost $0.025 per 1,000 state transitions, or roughly 1.5 Lambda GB-second. Express Workflow pricing matches Lambda pricing per GB-sec [validate]\u003C\u002Fli>\n\u003C\u002Ful>\n\u003Ch2>Related Refactorings\u003C\u002Fh2>\n\u003Cul>\n\u003Cli>\u003Ca href=\".\u002Fdirect_database_access\">Direct database access\u003C\u002Fa>\u003C\u002Fli>\n\u003C\u002Ful>\n",{"title":6},"Replace Lambda with Service Integration","## Description\nAs part of your AWS Step Functions workflow, if you want to integrate with other AWS Services like Amazon Rekognition to detect object in an image, run and wait for AWS Batch job, or run an Amazon Elastic Container Service (Amazon ECS) task and wait for it to complete, you had to write a custom AWS Lambda function to handle each step of that service integration.\n \nAn example of custom Lambda making Rekognition call might look as follows:\n\n```js\nconst aws = require('aws-sdk');\nconst rekognition = new aws.Rekognition();\n\nexports.handler = async (event,context, callback) => {\n    ...\n    result = await rekognition.detectLabels(params).promise();\n    ...\n}\n```\n![](\u002Fassets\u002Fexternal\u002Fguides\u002Frefactoring-serverless\u002Fassets\u002Fimages\u002Fservice_integration_original.png)  \n\n## Solution\nUse Step Functions' [SDK Service Integration](https:\u002F\u002Fdocs.aws.amazon.com\u002Fstep-functions\u002Flatest\u002Fdg\u002Fsupported-services-awssdk.html) to directly call each AWS Service's API directly from your worklow.\n\n![](\u002Fassets\u002Fexternal\u002Fguides\u002Frefactoring-serverless\u002Fassets\u002Fimages\u002Fservice_integration_refactored.png)\n\nSee the CDK implementation of this pattern in Typescript on [GitHub](https:\u002F\u002Fgithub.com\u002Faws-samples\u002Faws-refactoring-to-serverless\u002Fblob\u002Fmain\u002Fimplementation\u002Fservice_integration\u002FREADME.md).\n\n\n## Considerations \n\n#### Advantages\n* You eliminate a run-time element (AWS Lambda) and thus reduce cost and run-time complexity.\n* You reduce a little latency by eliminating the extra service hop.\n\n#### Limitation\n* You might lose the ability to decouple the API syntax from Step Functions, e.g. by setting defaults or post-processing results in the Lambda function.\n\n### Applicability\n\n* Service Integration can invoke almost all AWS SDK APIs. See [the documentation](https:\u002F\u002Fdocs.aws.amazon.com\u002Fstep-functions\u002Flatest\u002Fdg\u002Fsupported-services-awssdk.html#unsupported-api-actions-list) for limitations \n* Cost: If you can replace the Lambda invocation with a single Step Functions state, the Step Functions cost remains but you save the Lambda execution cost. if you require an additional step, e.g. a pass state, standard workflows cost $0.025 per 1,000 state transitions, or roughly 1.5 Lambda GB-second. Express Workflow pricing matches Lambda pricing per GB-sec \\[validate\\]\n\n## Related Refactorings\n- [Direct database access](.\u002Fdirect_database_access)\n",[9,10,11],"content\u002Fcontributors\u002Fgregor-hohpe.json","content\u002Fcontributors\u002Fsindhu-pillai.json","content\u002Fcontributors\u002Fbhuvan-annamreddi.json","LIST","Refactoring to Serverless","\u002Fcontent\u002Fguides\u002Frefactoring-serverless\u002Fservice_integration","2 min",[17,42],{"title":18,"content":19},"Introduction",[20],{"title":13,"order":21,"callout":22,"resources":26,"time":38,"path":39,"id":40,"link":41},1,{"title":23,"description":24,"link":25},"Watch the video","This session shows how you can refactor an existing serverless application to fully utilize AWS managed services and make service dependencies explicit, resulting in cleaner and more robust code.","https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=F7wxgWaccHs",[27,31,34],{"link":28,"text":29,"type":30},"https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=ttJAIQf7cTw","Building modern cloud applications? Think integration!","video",{"link":32,"text":33,"type":30},"https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=Ud9h1hJgoKk","Modern cloud applications - do they lock you in?",{"link":35,"text":36,"type":37},"https:\u002F\u002Fcdkpatterns.com\u002Fpatterns\u002F","CDK Patterns Collection","website","3 min","introduction","introduction.md","\u002Fcontent\u002Fguides\u002Frefactoring-serverless\u002Fintroduction",{"title":43,"content":44},"Refactorings",[45,50,55,58,64,69,74],{"title":46,"time":15,"path":47,"id":48,"link":49},"Extract Send Message","extract_send_message","extract_send_message.md","\u002Fcontent\u002Fguides\u002Frefactoring-serverless\u002Fextract_send_message",{"title":51,"time":15,"path":52,"id":53,"link":54},"Extract function invocation","extract_function_invocation","extract_function_invocation.md","\u002Fcontent\u002Fguides\u002Frefactoring-serverless\u002Fextract_function_invocation",{"title":6,"time":15,"path":56,"id":57,"link":14},"service_integration","service_integration.md",{"title":59,"time":60,"path":61,"id":62,"link":63},"Direct database access","1 min","direct_database_access","direct_database_access.md","\u002Fcontent\u002Fguides\u002Frefactoring-serverless\u002Fdirect_database_access",{"title":65,"time":60,"path":66,"id":67,"link":68},"Replace Polling with Callback","replace_polling_with_callback","replace_polling_with_callback.md","\u002Fcontent\u002Fguides\u002Frefactoring-serverless\u002Freplace_polling_with_callback",{"title":70,"time":15,"path":71,"id":72,"link":73},"Send Message via Pipes","send_message_via_pipes","send_message_via_pipes.md","\u002Fcontent\u002Fguides\u002Frefactoring-serverless\u002Fsend_message_via_pipes",{"title":75,"authors":76,"time":38,"path":78,"id":79,"link":80},"Convert Choreography to Orchestration",[77],"Bhuvan Annamreddi","choreography-to-orchestration","choreography-to-orchestration.md","\u002Fcontent\u002Fguides\u002Frefactoring-serverless\u002Fchoreography-to-orchestration",1792578866271]