{"id":458530,"date":"2025-05-04T15:00:26","date_gmt":"2025-05-04T15:00:26","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=458530"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=458530","title":{"rendered":"<span>\u041a\u0430\u043a \u044f \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u043b serverless OCR-\u0441\u0435\u0440\u0432\u0438\u0441 \u043d\u0430 AWS Lambda \u0438 Amazon Bedrock<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041d\u0435\u0434\u0430\u0432\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u043e \u043c\u043d\u043e\u0439 \u0432\u0441\u0442\u0430\u043b\u0430 \u0437\u0430\u0434\u0430\u0447\u0430: \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430 \u0438\u0437 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 (\u0441\u043a\u0430\u043d\u044b PDF, \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f PNG\/JPG) \u043d\u0430 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u0445 AWS. \u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u2013 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c <strong>Amazon Textract<\/strong> \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c <strong>Tesseract<\/strong> \u0432\u043d\u0443\u0442\u0440\u0438 Lambda. \u041e\u0434\u043d\u0430\u043a\u043e, \u043f\u043e\u0434\u0445\u043e\u0434 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <strong>Amazon Bedrock<\/strong> \u043c\u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0438\u0432\u043b\u0435\u043a\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u043c &#171;\u0442\u0430\u043d\u0446\u0435\u0432 \u0441 \u0431\u0443\u0431\u043d\u043e\u043c&#187; \u0432\u043e\u043a\u0440\u0443\u0433 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043e\u0442\u0432\u0435\u0442\u0430 Textract.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0437\u0430 \u043f\u0430\u0440\u0443 \u0447\u0430\u0441\u043e\u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u0431\u0435\u0437\u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0439 (serverless) OCR-\u0441\u0435\u0440\u0432\u0438\u0441 \u043d\u0430 AWS, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <strong>AWS Lambda<\/strong> \u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u0438\u0437 <strong>Amazon Bedrock<\/strong> \u0434\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u0430. \u0421\u0442\u0430\u0442\u044c\u044f \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u043e\u043f\u044b\u0442\u043d\u044b\u0445 AWS-\u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u043e\u0440\u043e\u0432, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0443\u0433\u043b\u0443\u0431\u0438\u043c\u0441\u044f \u0432 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443, \u043f\u043e\u043a\u0430\u0436\u0443 \u043a\u043e\u0434 (Terraform \u0434\u043b\u044f \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0438 Python \u0434\u043b\u044f Lambda), \u043e\u0431\u0441\u0443\u0434\u0438\u043c \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0438 \u043f\u0440\u0438\u043a\u0438\u043d\u0435\u043c \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0432 \u0440\u0435\u0433\u0438\u043e\u043d\u0435 <strong>eu-central-1 (\u0424\u0440\u0430\u043d\u043a\u0444\u0443\u0440\u0442)<\/strong>. \u041f\u043e\u0435\u0445\u0430\u043b\u0438!<\/p>\n<h3>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h3>\n<p>\u041f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0430\u044f \u0438\u0434\u0435\u044f \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u043b\u0430\u0441\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c Lambda-\u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0447\u0435\u0440\u0435\u0437 S3 Event Notification \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u041d\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0441\u0442\u0430\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e: <strong>\u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u044b\u043c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c \u0441 \u0442\u0440\u043e\u0442\u0442\u043b\u0438\u043d\u0433\u043e\u043c \u0438 \u043f\u0440\u0435\u0432\u044b\u0448\u0435\u043d\u0438\u0435\u043c \u043b\u0438\u043c\u0438\u0442\u0430 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 Lambda (concurrent executions)<\/strong> \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043e\u0431\u044a\u0435\u043c\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e: \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u043f\u0430\u0447\u043a\u0443 \u0438\u0437 500 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 S3. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u0442\u044c 500 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 Lambda-\u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u0415\u0441\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0442\u044f\u0436\u0451\u043b\u0430\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u0435\u043b\u0430\u0435\u0442 \u0432\u044b\u0437\u043e\u0432 \u043a Bedrock \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e 5-10 \u0441\u0435\u043a\u0443\u043d\u0434), \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0443\u043f\u0435\u0440\u0435\u0442\u044c\u0441\u044f \u0432 \u043b\u0438\u043c\u0438\u0442 \u043d\u0430 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 1000 \u043d\u0430 \u0430\u043a\u043a\u0430\u0443\u043d\u0442). \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043f\u0440\u0438 \u0440\u0435\u0437\u043a\u043e\u043c \u0432\u0441\u043f\u043b\u0435\u0441\u043a\u0435 \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0442\u0440\u0430\u0444\u0438\u043a\u0430 S3 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 <strong>\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 (rate limiting)<\/strong> \u0434\u043b\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u2013 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043b\u0435\u0442\u044f\u0442 \u0431\u0435\u0437 \u0443\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f.<\/p>\n<h4>\u041a\u0430\u043a \u044f \u0440\u0435\u0448\u0438\u043b \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443:<\/h4>\n<p>\u042f \u0437\u0430\u043c\u0435\u043d\u0438\u043b \u043f\u0440\u044f\u043c\u043e\u0439 \u0432\u044b\u0437\u043e\u0432 Lambda \u0441 S3 \u043d\u0430 <strong>\u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u0431\u0443\u0444\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u0447\u0435\u0440\u0435\u0437 EventBridge + SQS + SNS<\/strong>. \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u044d\u0442\u043e \u0442\u0430\u043a:<\/p>\n<ol>\n<li>\n<p><strong>\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0441\u044f \u0432 S3<\/strong> \u2013 \u044d\u0442\u043e \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u0438\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0432 <strong>EventBridge<\/strong>. \u041c\u043d\u043e\u0433\u0438\u0435 \u043d\u0435 \u0437\u043d\u0430\u044e\u0442, \u043d\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f S3 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432 <strong>default event bus<\/strong>. \u041c\u044b \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c <strong>EventBridge Rule<\/strong>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u0442 \u043d\u0443\u0436\u043d\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>PutObject<\/code> \u0432 \u043d\u0443\u0436\u043d\u043e\u043c \u0431\u0430\u043a\u0435\u0442\u0435 \u0441 \u043d\u0443\u0436\u043d\u044b\u043c \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u043e\u043c <code>uploads\/<\/code>).<\/p>\n<\/li>\n<li>\n<p>\u042d\u0442\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043c\u044b <strong>\u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0432 SQS<\/strong> \u0438 \u0434\u0430\u043b\u0435\u0435 \u0443\u0436\u0435 \u0432 \u0442\u043e\u043f\u0438\u043a <strong>SNS<\/strong>:<\/p>\n<ul>\n<li>\n<p>\u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0434\u043d\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432 <strong>SQS<\/strong> \u2013 \u0434\u043b\u044f \u0431\u0443\u0444\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u043f\u043e\u0442\u043e\u043a\u0430;<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 <strong>Lambda-\u0444\u0443\u043d\u043a\u0446\u0438\u044e<\/strong>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u043e\u0441\u0442\u0430\u0451\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0438\u0437 \u0442\u043e\u043f\u0438\u043a\u0430 SNS \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 OCR-\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0440\u0435\u0448\u0430\u0435\u0442 \u0441\u0440\u0430\u0437\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0434\u0430\u0447:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 <strong>\u043e\u0442\u0434\u0435\u043b\u0438\u0442\u044c<\/strong> \u043c\u043e\u043c\u0435\u043d\u0442 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0444\u0430\u0439\u043b\u0430 \u0438 \u043d\u0430\u0447\u0430\u043b\u043e \u0435\u0433\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0427\u0435\u0440\u0435\u0437 <strong>SQS<\/strong> \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0440\u0430\u0441\u0442\u0451\u0442 \u2013 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0449\u0451 \u043e\u0434\u043d\u0443 Lambda \u0438\u043b\u0438 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440).<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c <strong>\u0434\u0435\u0434\u0443\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044e<\/strong>, <strong>\u0440\u0435\u0442\u0440\u0430\u0438<\/strong>, \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0447\u0435\u0440\u0435\u0437 EventBridge.<\/p>\n<\/li>\n<\/ul>\n<h4>\u0412\u0442\u043e\u0440\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430: \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432 SQS<\/h4>\n<p>\u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u044f \u0445\u043e\u0442\u0435\u043b, \u0447\u0442\u043e\u0431\u044b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 OCR \u043f\u043e\u043f\u0430\u0434\u0430\u043b \u0441\u0440\u0430\u0437\u0443 \u0432\u043e \u0432\u0442\u043e\u0440\u0443\u044e <strong>SQS<\/strong> \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0439 Lambda. \u041d\u043e \u0442\u0443\u0442 \u043c\u044b \u043d\u0430\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u043c\u0441\u044f \u043d\u0430 \u0441\u0443\u0440\u043e\u0432\u043e\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435: <strong>\u0440\u0430\u0437\u043c\u0435\u0440 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432 SQS \u2014 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 256 \u041a\u0411<\/strong>. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u044b\u043c, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0435\u0441\u043b\u0438 \u043c\u043e\u0434\u0435\u043b\u044c Bedrock \u0432\u0435\u0440\u043d\u0451\u0442 \u0434\u043b\u0438\u043d\u043d\u044b\u0439 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u043d\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u0438\u043b\u0438 structured output (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, JSON \u0441 \u043a\u0443\u0447\u0435\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 PDF-\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430).<\/p>\n<h4>\u041a\u0430\u043a \u043e\u0431\u043e\u0439\u0442\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435:<\/h4>\n<p>\u042f \u0438\u0437\u043c\u0435\u043d\u0438\u043b \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<ul>\n<li>\n<p><strong>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b Bedrock \u043a\u043b\u0430\u0434\u0451\u0442\u0441\u044f \u0432 S3<\/strong> (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u0431\u0430\u043a\u0435\u0442 <code>ocr-results-bucket\/uuid.json<\/code>).<\/p>\n<\/li>\n<li>\n<p>\u0412 SQS \u0438\u0434\u0451\u0442 <strong>\u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0441\u044b\u043b\u043a\u0430<\/strong> \u043d\u0430 \u0444\u0430\u0439\u043b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430: <code>{ \"resultKey\": \"ocr-results\/123.json\", \"sourceKey\": \"uploads\/filename.png\" }<\/code>.<\/p>\n<\/li>\n<li>\n<p>Lambda-\u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0447\u0438\u0442\u0430\u0435\u0442 \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0434\u0442\u044f\u0433\u0438\u0432\u0430\u0435\u0442 JSON \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0438\u0437 S3 \u0438 \u043f\u0438\u0448\u0435\u0442 \u043d\u0443\u0436\u043d\u044b\u0435 \u043f\u043e\u043b\u044f \u0432 DynamoDB.<\/p>\n<\/li>\n<\/ul>\n<p>\u042d\u0442\u043e \u043d\u0430\u0434\u0451\u0436\u043d\u043e, \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e \u0438 \u0443\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043b\u0438\u043c\u0438\u0442\u044b. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u0435\u0441\u043b\u0438 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u0440\u0443\u0447\u043d\u044b\u0435 \u0440\u0435\u0442\u0440\u0430\u0438 \u0438\u043b\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a, \u0443\u0434\u043e\u0431\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0442\u0430\u0442\u044c S3-\u0444\u0430\u0439\u043b.<\/p>\n<p>\u0418\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430:<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u0444\u0430\u0439\u043b \u0432 S3 \u0432 \u043f\u0430\u043f\u043a\u0443 <code>uploads\/<\/code><\/p>\n<\/li>\n<li>\n<p>EventBridge \u043b\u043e\u0432\u0438\u0442 <code>PutObject<\/code> \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0435\u0433\u043e \u0432 SNS topic:<\/p>\n<ul>\n<li>\n<p>\u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c SQS (\u0431\u0443\u0444\u0435\u0440);<\/p>\n<\/li>\n<li>\n<p>\u0438 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 Lambda <code>InvokeBedrock<\/code> (\u0447\u0435\u0440\u0435\u0437 SNS);<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>Lambda \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 Bedrock, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 OCR \u0432 S3 (\u0432 <code>ocr-results\/<\/code>) \u0438 \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432 SQS c \u0441\u0441\u044b\u043b\u043a\u043e\u0439 \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0442\u043e\u0440\u0430\u044f Lambda <code>SaveToDB<\/code> \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043f\u043e\u0434\u0442\u044f\u0433\u0438\u0432\u0430\u0435\u0442 JSON \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0438\u0437 S3 \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0432 DynamoDB \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u044d\u0442\u043e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u0440\u0435\u0432\u044b\u0448\u0435\u043d\u0438\u044f \u043b\u0438\u043c\u0438\u0442\u043e\u0432 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 DynamoDB \u0438 \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u043f\u0440\u0438 \u0447\u0442\u0435\u043d\u0438\u0438, \u0432\u0435\u0434\u044c \u043f\u043e\u043b\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 \u0438\u0437 S3.<\/p>\n<\/li>\n<\/ol>\n<p>\u0412\u0441\u0451 \u2014 \u043c\u044b \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0440\u0438\u0441\u043a\u0438 \u0442\u0440\u043e\u0442\u0442\u043b\u0438\u043d\u0433\u0430, \u0441\u043e\u0431\u043b\u044e\u043b\u0438 \u043b\u0438\u043c\u0438\u0442\u044b SQS \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b\u0438 serverless-\u043f\u043e\u0434\u0445\u043e\u0434.<\/p>\n<h3>Terraform \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u0430, \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0441\u0451 \u044d\u0442\u043e \u0432 Terraform. \u041d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f:<\/p>\n<ul>\n<li>\n<p>S3-\u0431\u0430\u043a\u0435\u0442 \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>EventBridge Rule<\/p>\n<\/li>\n<li>\n<p>SNS-\u0442\u043e\u043f\u0438\u043a \u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438 (\u043d\u0430 Lambda \u0438 SQS)<\/p>\n<\/li>\n<li>\n<p>\u041e\u0447\u0435\u0440\u0435\u0434\u044c SQS<\/p>\n<\/li>\n<li>\n<p>Lambda-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 (InvokeBedrock \u0438 SaveToDB)<\/p>\n<\/li>\n<li>\n<p>IAM \u0440\u043e\u043b\u0438 \u0438 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 \u0434\u043b\u044f Lambda<\/p>\n<\/li>\n<li>\n<p>DynamoDB \u0442\u0430\u0431\u043b\u0438\u0446\u0430<\/p>\n<\/li>\n<li>\n<p>S3-\u0431\u0430\u043a\u0435\u0442 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 OCR<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u043e\u0434 \u043d\u0438\u0436\u0435 \u0440\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043f\u043e\u0434 \u043d\u0430\u0448\u0443 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 \u0438 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442:<\/p>\n<ul>\n<li>\n<p>\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 SQS<\/p>\n<\/li>\n<li>\n<p>\u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0432 S3<\/p>\n<\/li>\n<li>\n<p>\u0444\u0430\u043d-\u0430\u0443\u0442 \u0447\u0435\u0440\u0435\u0437 SNS<\/p>\n<\/li>\n<li>\n<p>\u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e \u0440\u0438\u0441\u043a\u043e\u0432 \u0442\u0440\u043e\u0442\u0442\u043b\u0438\u043d\u0433\u0430<\/p>\n<\/li>\n<\/ul>\n<details class=\"spoiler\">\n<summary>main.tf<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"vhdl\">provider \"aws\" {   region = \"eu-central-1\" }  # S3 buckets resource \"aws_s3_bucket\" \"uploads\" {   bucket = \"ocr-input-documents\" }  resource \"aws_s3_bucket\" \"results\" {   bucket = \"ocr-processed-results\" }  # DynamoDB \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445 (\u043a\u043b\u044e\u0447\u0435\u0439) resource \"aws_dynamodb_table\" \"ocr_index\" {   name         = \"OCRResultsIndex\"   billing_mode = \"PAY_PER_REQUEST\"   hash_key     = \"Id\"   attribute {     name = \"Id\"     type = \"S\"   } }  # SNS Topic resource \"aws_sns_topic\" \"ocr_topic\" {   name = \"ocr-trigger-topic\" }  # SQS Queue resource \"aws_sqs_queue\" \"ocr_queue\" {   name = \"ocr-processing-queue\" }  # \u041f\u043e\u0434\u043f\u0438\u0441\u043a\u0430 SQS \u043a SNS resource \"aws_sns_topic_subscription\" \"sqs_sub\" {   topic_arn = aws_sns_topic.ocr_topic.arn   protocol  = \"sqs\"   endpoint  = aws_sqs_queue.ocr_queue.arn }  # \u041f\u043e\u0434\u043f\u0438\u0441\u043a\u0430 Lambda \u043d\u0430 SNS (InvokeBedrock) resource \"aws_lambda_permission\" \"allow_sns_invoke_lambda\" {   statement_id  = \"AllowExecutionFromSNS\"   action        = \"lambda:InvokeFunction\"   function_name = aws_lambda_function.invoke_bedrock.function_name   principal     = \"sns.amazonaws.com\"   source_arn    = aws_sns_topic.ocr_topic.arn }  resource \"aws_sns_topic_subscription\" \"lambda_sub\" {   topic_arn = aws_sns_topic.ocr_topic.arn   protocol  = \"lambda\"   endpoint  = aws_lambda_function.invoke_bedrock.arn }  # EventBridge Rule: \u043e\u0442\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c PutObject \u0432 \u0431\u0430\u043a\u0435\u0442\u0435 resource \"aws_cloudwatch_event_rule\" \"s3_put\" {   name        = \"ocr-upload-trigger\"   event_pattern = jsonencode({     \"source\": [\"aws.s3\"],     \"detail-type\": [\"Object Created\"],     \"detail\": {       \"bucket\": {\"name\": [aws_s3_bucket.uploads.bucket]},       \"object\": {\"key\": [{\"prefix\": \"uploads\/\"}]}     }   }) }  # Target \u2014 SNS resource \"aws_cloudwatch_event_target\" \"to_sns\" {   rule      = aws_cloudwatch_event_rule.s3_put.name   target_id = \"SendToSNS\"   arn       = aws_sns_topic.ocr_topic.arn }  resource \"aws_lambda_function\" \"invoke_bedrock\" {   function_name = \"InvokeBedrockOCR\"   role          = aws_iam_role.lambda_role.arn   handler       = \"invoke.lambda_handler\"   runtime       = \"python3.10\"   filename      = \"lambda_invoke.zip\"    environment {     variables = {       RESULT_BUCKET = aws_s3_bucket.results.bucket       QUEUE_URL     = aws_sqs_queue.ocr_queue.id     }   } }  resource \"aws_lambda_function\" \"save_result\" {   function_name = \"SaveOCRToDynamo\"   role          = aws_iam_role.lambda_role.arn   handler       = \"save.lambda_handler\"   runtime       = \"python3.10\"   filename      = \"lambda_save.zip\"    environment {     variables = {       TABLE_NAME    = aws_dynamodb_table.ocr_index.name       RESULT_BUCKET = aws_s3_bucket.results.bucket     }   } }  # \u041f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f resource \"aws_lambda_event_source_mapping\" \"sqs_trigger\" {   event_source_arn = aws_sqs_queue.ocr_queue.arn   function_name    = aws_lambda_function.save_result.arn   batch_size       = 1 }  # IAM Role + Policy resource \"aws_iam_role\" \"lambda_role\" {   name = \"ocr_lambda_role\"   assume_role_policy = jsonencode({     Version = \"2012-10-17\",     Statement = [{       Effect = \"Allow\",       Principal = { Service = \"lambda.amazonaws.com\" },       Action = \"sts:AssumeRole\"     }]   }) }  resource \"aws_iam_role_policy\" \"lambda_policy\" {   name = \"ocr_lambda_inline\"   role = aws_iam_role.lambda_role.id   policy = jsonencode({     Version = \"2012-10-17\",     Statement = [       {         Effect = \"Allow\",         Action = [\"s3:GetObject\", \"s3:PutObject\"],         Resource = [           \"${aws_s3_bucket.uploads.arn}\/*\",           \"${aws_s3_bucket.results.arn}\/*\"         ]       },       {         Effect = \"Allow\",         Action = [\"bedrock:InvokeModel\"],         Resource = \"*\"       },       {         Effect = \"Allow\",         Action = [\"dynamodb:PutItem\"],         Resource = aws_dynamodb_table.ocr_index.arn       },       {         Effect = \"Allow\",         Action = [\"sqs:SendMessage\", \"sqs:ReceiveMessage\", \"sqs:DeleteMessage\"],         Resource = aws_sqs_queue.ocr_queue.arn       },       {         Effect = \"Allow\",         Action = [           \"logs:CreateLogGroup\",           \"logs:CreateLogStream\",           \"logs:PutLogEvents\"         ],         Resource = \"arn:aws:logs:*:*:*\"       }     ]   }) }<\/code><\/pre>\n<\/div>\n<\/details>\n<h3>Lambda-\u0444\u0443\u043d\u043a\u0446\u0438\u044f: \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 PDF \u0438 \u0432\u044b\u0437\u043e\u0432 Bedrock<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u043f\u0435\u0440\u0432\u0443\u044e Lambda-\u0444\u0443\u043d\u043a\u0446\u0438\u044e (<code>InvokeBedrock<\/code>), \u043a\u043e\u0442\u043e\u0440\u0430\u044f:<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435 \u0438\u0437 SNS \u043e \u043d\u043e\u0432\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0435 \u0432 S3<\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u0444\u0430\u0439\u043b PDF \u0438\u043b\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u044d\u0442\u043e PDF \u2014 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442 \u0435\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432 Bedrock, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u043e\u0434\u0435\u043b\u0438 Claude 3 \u0443\u043c\u0435\u044e\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c PDF-\u0444\u0430\u0439\u043b\u044b \u0431\u0435\u0437 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u0438; \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 (JPEG, PNG), \u043e\u043d\u043e \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 base64 \u0438 \u0442\u0430\u043a\u0436\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u043c\u043e\u0434\u0435\u043b\u0438<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442 Amazon Bedrock \u0441 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u044b\u043c \u0444\u0430\u0439\u043b\u0430 \u0438 \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u043e\u0442\u0432\u0435\u0442<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 S3 \u0438 \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043d\u0435\u0433\u043e \u0432 SQS<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>lambda_invoke_bedrock.py<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import os import json import base64 import boto3 import mimetypes from urllib.parse import unquote_plus from aws_lambda_powertools import Logger  logger = Logger(service=\"ocr-bedrock\")  s3_client = boto3.client(\"s3\") bedrock_client = boto3.client(\"bedrock-runtime\") sqs_client = boto3.client(\"sqs\")  RESULT_BUCKET = os.environ.get(\"RESULT_BUCKET\") QUEUE_URL = os.environ.get(\"QUEUE_URL\") MODEL_ID = \"anthropic.claude-3-sonnet-20240229-v1:0\"   @logger.inject_lambda_context def lambda_handler(event, context):  # noqa: E501     \"\"\"Lambda function to process S3 events and invoke Bedrock model for OCR.      Args:         event (dict): The event data from S3.         context (LambdaContext): The context object for the Lambda function.      Raises:         Exception: If there is an error processing the file or invoking the model.     \"\"\"     for record in event[\"Records\"]:         try:             message = json.loads(record[\"Sns\"][\"Message\"])             bucket = message[\"detail\"][\"bucket\"][\"name\"]             key = unquote_plus(message[\"detail\"][\"object\"][\"key\"])             logger.info(f\"Processing file: s3:\/\/{bucket}\/{key}\")              obj = s3_client.get_object(Bucket=bucket, Key=key)             content = obj[\"Body\"].read()             mime_type, _ = mimetypes.guess_type(key)              prompt_text = \"Extract all the text from the document and return it as plain text.\"              if mime_type not in [\"image\/jpeg\", \"image\/png\", \"application\/pdf\"]:                 logger.warning(f\"Unsupported MIME type: {mime_type}\")                 continue              encoded = base64.b64encode(content).decode(\"utf-8\")              request_body = {                 \"anthropic_version\": \"bedrock-2023-05-31\",                 \"messages\": [                     {                         \"role\": \"user\",                         \"content\": [                             {\"type\": \"text\", \"text\": prompt_text},                             {                                 \"type\": \"document\" if mime_type in [\"application\/pdf\"] else \"image\",                                 \"source\": {                                     \"type\": \"base64\",                                     \"media_type\": mime_type,                                     \"data\": encoded,                                 },                             },                         ],                     },                 ],             }              response = bedrock_client.invoke_model(                 modelId=MODEL_ID, body=json.dumps(request_body), contentType=\"application\/json\"             )              response_body = response[\"body\"].read().decode(\"utf-8\")             result_data = json.loads(response_body)              output_text = result_data.get(\"outputs\", [{}])[0].get(\"content\", [{}])[0].get(\"text\", \"\")              result_key = key.replace(\"uploads\/\", \"ocr-results\/\") + \".json\"             s3_client.put_object(                 Bucket=RESULT_BUCKET,                 Key=result_key,                 Body=json.dumps({\"text\": output_text, \"source\": key}, ensure_ascii=False).encode(\"utf-8\"),             )              sqs_client.send_message(                 QueueUrl=QUEUE_URL,                 MessageBody=json.dumps({\"result_key\": result_key, \"source_key\": key}),             )              logger.info(f\"Result saved to s3:\/\/{RESULT_BUCKET}\/{result_key} and queued in SQS\")          except Exception as e:             logger.exception(f\"Error processing file: {e}\")             raise <\/code><\/pre>\n<\/div>\n<\/details>\n<h4>\u041e\u0431\u0449\u0438\u0439 \u0441\u043c\u044b\u0441\u043b \u0440\u0430\u0431\u043e\u0442\u044b InvokeBedrock Lambda<\/h4>\n<p>\u0424\u0443\u043d\u043a\u0446\u0438\u044f \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u043f\u0440\u0438 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0438\u0437 SNS, \u0447\u0438\u0442\u0430\u0435\u0442 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0438\u0437 S3 (PDF \u0438\u043b\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435), \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442 \u0435\u0433\u043e \u0432 Amazon Bedrock (\u043c\u043e\u0434\u0435\u043b\u044c Claude 3), \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0442\u0435\u043a\u0441\u0442, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0435\u0433\u043e \u0432 S3, \u0430 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c SQS.<\/p>\n<p><strong>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u0435 \u043f\u043e \u0448\u0430\u0433\u0430\u043c:<\/strong><\/p>\n<ol>\n<li>\n<p>\u041b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f<\/p>\n<pre><code class=\"python\">from aws_lambda_powertools import Logger logger = Logger(service=\"ocr-bedrock\")<\/code><\/pre>\n<p>\u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c aws-lambda-powertools \u0434\u043b\u044f \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e \u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f. \u0412\u0441\u0435 \u043b\u043e\u0433\u0438 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043c\u0430\u0440\u043a\u0438\u0440\u0443\u044e\u0442\u0441\u044f ID \u0432\u044b\u0437\u043e\u0432\u0430 Lambda, \u0438 \u044d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u043f\u0440\u0438 \u043e\u0442\u043b\u0430\u0434\u043a\u0435.<\/p>\n<\/li>\n<li>\n<p>\u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u043f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443 \u0438\u0437 \u0441\u043e\u0431\u044b\u0442\u0438\u044f<\/p>\n<pre><code class=\"python\">message = json.loads(record[\"Sns\"][\"Message\"]) bucket = message[\"detail\"][\"bucket\"][\"name\"] key = unquote_plus(message[\"detail\"][\"object\"][\"key\"])<\/code><\/pre>\n<p>SNS \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 S3-\u0441\u043e\u0431\u044b\u0442\u0438\u0435. \u041c\u044b \u0434\u043e\u0441\u0442\u0430\u0451\u043c \u0438\u043c\u044f \u0431\u0430\u043a\u0435\u0442\u0430 \u0438 \u043a\u043b\u044e\u0447 \u0444\u0430\u0439\u043b\u0430.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u0444\u0430\u0439\u043b\u0430 \u0438\u0437 S3<\/p>\n<pre><code class=\"python\">obj = s3_client.get_object(Bucket=bucket, Key=key) content = obj[\"Body\"].read()<\/code><\/pre>\n<p>\u0417\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0444\u0430\u0439\u043b\u0430 \u0432 \u043f\u0430\u043c\u044f\u0442\u044c \u0434\u043b\u044f \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u0439 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0432 Bedrock.<\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c MIME-\u0442\u0438\u043f<\/p>\n<pre><code class=\"python\">mime_type,  = mimetypes.guesstype(key)<\/code><\/pre>\n<p>\u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0430\u043c \u043f\u043e\u043d\u044f\u0442\u044c, \u0447\u0442\u043e \u0437\u0430 \u0442\u0438\u043f \u0444\u0430\u0439\u043b\u0430 \u2014 PDF \u0438\u043b\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435.<\/p>\n<\/li>\n<li>\n<p>\u041a\u043e\u0434\u0438\u0440\u0443\u0435\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435<\/p>\n<pre><code class=\"python\">encoded = base64.b64encode(content).decode(\"utf-8\")<\/code><\/pre>\n<p>\u0414\u043b\u044f \u043c\u043e\u0434\u0435\u043b\u0435\u0439 Bedrock \u043c\u0443\u043b\u044c\u0442\u0438\u043c\u043e\u0434\u0430\u043b\u044c\u043d\u044b\u0439 \u0432\u0432\u043e\u0434 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u043a\u0430\u043a base64.<\/p>\n<\/li>\n<li>\n<p>\u0424\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c prompt \u0438 payload<\/p>\n<pre><code class=\"python\">prompt_text = \"Extract all the text ...\" ...  request_body = {\"messages\": [...]}<\/code><\/pre>\n<p>\u041c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u043c\u043e\u0434\u0435\u043b\u0438 \u0442\u0435\u043a\u0441\u0442\u043e\u0432\u0443\u044e \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e + \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\/\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442.<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0437\u043e\u0432 Bedrock<\/p>\n<pre><code class=\"python\">response = bedrock_client.invoke_model(...) response_body = response[\"body\"].read().decode(\"utf-8\")<\/code><\/pre>\n<p>\u041c\u043e\u0434\u0435\u043b\u044c \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 (\u0442\u0435\u043a\u0441\u0442 \u0432 JSON).<\/p>\n<\/li>\n<li>\n<p>\u041f\u0430\u0440\u0441\u0438\u043d\u0433 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430<\/p>\n<pre><code class=\"python\">result_data = json.loads(response_body) output_text = result_data.get(\"outputs\", ...).get(\"text\", \"\")<\/code><\/pre>\n<p>\u041c\u044b \u043f\u044b\u0442\u0430\u0435\u043c\u0441\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442 \u0438\u0437 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043e\u0442\u0432\u0435\u0442\u0430 \u043c\u043e\u0434\u0435\u043b\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 S3<\/p>\n<pre><code class=\"python\">result_key = key.replace(\"uploads\/\", \"ocr-results\/\") + \".json\" s3_client.put_object(..., Key=result_key, Body=json.dumps(...))<\/code><\/pre>\n<p>\u0420\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u043d\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442\u0441\u044f \u0432 S3 \u043a\u0430\u043a JSON-\u0444\u0430\u0439\u043b.<\/p>\n<\/li>\n<li>\n<p>\u041f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 SQS<\/p>\n<pre><code class=\"python\">sqs_client.send_message(     QueueUrl=QUEUE_URL,     MessageBody=json.dumps({\"result_key\": ..., \"source_key\": ...}) )<\/code><\/pre>\n<p>\u0412 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043c\u044b \u043a\u043b\u0430\u0434\u0451\u043c \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442, \u043d\u0435 \u0441\u0430\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u2014 \u0447\u0442\u043e\u0431\u044b \u043d\u0435 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0442\u044c \u043b\u0438\u043c\u0438\u0442 \u0432 256 \u041a\u0411.<\/p>\n<\/li>\n<li>\n<p>\u041e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a<\/p>\n<pre><code class=\"python\">except Exception as e:     logger.exception(...)<\/code><\/pre>\n<p>\u041e\u0448\u0438\u0431\u043a\u0438 \u043b\u043e\u0433\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0432 CloudWatch \u0441 \u043f\u043e\u043b\u043d\u044b\u043c stack trace.<\/p>\n<\/li>\n<\/ol>\n<h3>Lambda-\u0444\u0443\u043d\u043a\u0446\u0438\u044f: \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 \u0441\u0441\u044b\u043b\u043a\u0438 \u0432 DynamoDB<\/h3>\n<p>\u0412\u0442\u043e\u0440\u0430\u044f \u0444\u0443\u043d\u043a\u0446\u0438\u044f (<code>SaveOCRToDynamo<\/code>) \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043f\u0440\u0438 \u043f\u043e\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0438 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c SQS. \u041e\u043d\u0430 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u043e\u0441\u0442\u0430\u044f \u043f\u043e \u043b\u043e\u0433\u0438\u043a\u0435:<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u2014 \u044d\u0442\u043e JSON \u0441 \u043f\u043e\u043b\u044f\u043c\u0438 <code>result_key<\/code> \u0438 <code>source_key<\/code><\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u044d\u0442\u0443 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 DynamoDB:<\/p>\n<ul>\n<li>\n<p><code>Id<\/code> \u2014 UUID \u0438\u043b\u0438 <code>messageId<\/code><\/p>\n<\/li>\n<li>\n<p><code>SourceFile<\/code> \u2014 \u043f\u0443\u0442\u044c \u043a \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c\u0443 \u0444\u0430\u0439\u043b\u0443 \u0432 S3<\/p>\n<\/li>\n<li>\n<p><code>ResultFile<\/code> \u2014 \u043f\u0443\u0442\u044c \u043a JSON \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0432 S3<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u0434\u0430:<\/p>\n<details class=\"spoiler\">\n<summary>lambda_savedb.py<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import os import json import boto3 from aws_lambda_powertools import Logger  logger = Logger(service=\"ocr-save\") dynamodb = boto3.resource(\"dynamodb\") table = dynamodb.Table(os.environ.get(\"TABLE_NAME\"))  @logger.inject_lambda_context def lambda_handler(event, context):     for record in event[\"Records\"]:         try:             body = json.loads(record[\"body\"])             result_key = body[\"result_key\"]             source_key = body.get(\"source_key\", \"unknown\")             record_id = record.get(\"messageId\")              item = {                 \"Id\": record_id,                 \"SourceFile\": source_key,                 \"ResultFile\": result_key             }             table.put_item(Item=item)             logger.info(f\"Saved result reference for {source_key} to DynamoDB\")          except Exception as e:             logger.exception(f\"Error saving result to DynamoDB: {e}\")<\/code><\/pre>\n<\/div>\n<\/details>\n<p>\u0422\u0430\u043a\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c, \u043c\u044b \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c <strong>\u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442<\/strong>, \u0430 \u043d\u0435 \u0432\u0435\u0441\u044c \u0442\u0435\u043a\u0441\u0442, \u0447\u0442\u043e \u043f\u043e\u043c\u043e\u0433\u0430\u0435\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043b\u0438\u043c\u0438\u0442\u043e\u0432 DynamoDB \u043d\u0430 \u0440\u0430\u0437\u043c\u0435\u0440 \u0437\u0430\u043f\u0438\u0441\u0438 (400 \u041a\u0411) \u0438 \u0438\u0437\u0431\u044b\u0442\u043e\u0447\u043d\u043e\u0433\u043e \u0447\u0442\u0435\u043d\u0438\u044f. \u0414\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u043e\u043b\u043d\u043e\u043c\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0443 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u043e \u043a\u043b\u044e\u0447\u0443 <code>ResultFile<\/code> (s3:\/\/&#8230;).<\/p>\n<h3>\u041c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435 \u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f<\/h3>\n<p>\u0412\u0441\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043f\u043e\u0441\u0442\u0440\u043e\u0435\u043d\u0430 \u043f\u043e \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 &#171;event-driven&#187; \u0438 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e serverless, \u0447\u0442\u043e \u0434\u0430\u0451\u0442 \u043e\u0442\u043b\u0438\u0447\u043d\u044b\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0438 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p><strong>Lambda:<\/strong> \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u0442\u0441\u044f. \u0415\u0441\u043b\u0438 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0441\u044f 1000+ \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432, AWS \u043f\u043e\u0434\u043d\u0438\u043c\u0430\u0435\u0442 \u0441\u0442\u043e\u043b\u044c\u043a\u043e \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440\u043e\u0432, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u043e (\u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 \u043b\u0438\u043c\u0438\u0442\u0430 concurrent executions \u2014 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 1000). \u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043b\u0438\u043c\u0438\u0442 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043d\u044f\u0442\u044c \u0447\u0435\u0440\u0435\u0437 \u0437\u0430\u043f\u0440\u043e\u0441 \u0432 Support.<\/p>\n<\/li>\n<li>\n<p><strong>SQS:<\/strong> \u0440\u0430\u0437\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u0438 \u0433\u0430\u0440\u0430\u043d\u0442\u0438\u0440\u0443\u0435\u0442 \u0431\u0443\u0444\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044e. \u0414\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 Lambda \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043d\u0435 \u0441\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f, \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043d\u0430\u0434\u0451\u0436\u043d\u043e \u043b\u0435\u0436\u0430\u0442 \u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u0438.<\/p>\n<\/li>\n<li>\n<p><strong>SNS:<\/strong> \u0444\u0430\u043d-\u0430\u0443\u0442 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a\u043e\u0432 \u2014 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u043b\u044f \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433\u0430, \u0430\u043d\u0430\u043b\u0438\u0442\u0438\u043a\u0438 \u0438\u043b\u0438 \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u043e\u0432 \u043d\u0430 \u0434\u043e\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443.<\/p>\n<\/li>\n<li>\n<p><strong>DynamoDB:<\/strong> \u0440\u0435\u0436\u0438\u043c On-Demand \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0435 \u0434\u0443\u043c\u0430\u0442\u044c \u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 throughput. \u0412\u0430\u0436\u043d\u043e \u043b\u0438\u0448\u044c \u043d\u0435 \u043f\u0440\u0435\u0432\u044b\u0448\u0430\u0442\u044c \u0440\u0430\u0437\u043c\u0435\u0440 \u0437\u0430\u043f\u0438\u0441\u0438 \u0438 \u0441\u043b\u0435\u0434\u0438\u0442\u044c \u0437\u0430 partition key.<\/p>\n<\/li>\n<li>\n<p><strong>S3:<\/strong> \u043e\u0442\u043b\u0438\u0447\u043d\u043e \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0438 \u0441\u043b\u0443\u0436\u0438\u0442 \u043a\u0430\u043a \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b\u043e\u0432, \u0442\u0430\u043a \u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432.<\/p>\n<\/li>\n<li>\n<p><strong>Bedrock:<\/strong> \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0435 \u0443\u0437\u043a\u043e\u0435 \u043c\u0435\u0441\u0442\u043e. \u0412\u0430\u0436\u043d\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u0442\u044c:<\/p>\n<ul>\n<li>\n<p>\u041e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043d\u0430 \u0440\u0430\u0437\u043c\u0435\u0440 \u0437\u0430\u043f\u0440\u043e\u0441\u0430 \u2014 ~5MB<\/p>\n<\/li>\n<li>\n<p>\u0422\u043e\u043a\u0435\u043d\u043d\u044b\u0435 \u043b\u0438\u043c\u0438\u0442\u044b \u0443 \u043c\u043e\u0434\u0435\u043b\u0438 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, max_tokens=4096 \u0438\u043b\u0438 8192)<\/p>\n<\/li>\n<li>\n<p>\u0412\u043e\u0437\u043c\u043e\u0436\u043d\u0430 \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0430 \u043f\u0440\u0438 \u0438\u043d\u0444\u0435\u0440\u0435\u043d\u0441\u0435 (\u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u0438\u0445 PDF)<\/p>\n<\/li>\n<li>\n<p>\u041d\u0435 \u0432\u0441\u0435 \u043c\u043e\u0434\u0435\u043b\u0438 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0440\u0435\u0433\u0438\u043e\u043d\u0435 \u2014 \u043b\u0443\u0447\u0448\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c <code>eu-central-1<\/code> \u0438\u043b\u0438 <code>us-east-1<\/code><\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>\u0415\u0441\u043b\u0438 \u043e\u0431\u044a\u0451\u043c \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u0441\u044f \u0441\u0442\u0430\u0431\u0438\u043b\u044c\u043d\u044b\u043c \u0438 \u0431\u043e\u043b\u044c\u0448\u0438\u043c \u2014 \u043c\u043e\u0436\u043d\u043e \u0440\u0430\u0441\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c <strong>Provisioned Throughput<\/strong> \u0434\u043b\u044f Bedrock, \u0447\u0442\u043e\u0431\u044b \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u0445\u043e\u043b\u043e\u0434\u043d\u044b\u0445 \u0441\u0442\u0430\u0440\u0442\u043e\u0432 \u0438 \u0437\u0430\u0434\u0435\u0440\u0436\u0435\u043a.<\/p>\n<h4>\u0414\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f Amazon Bedrock \u043f\u043e \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0435<\/h4>\n<p>Amazon Bedrock, \u043d\u0435\u0441\u043c\u043e\u0442\u0440\u044f \u043d\u0430 \u0432\u0441\u044e \u043c\u0430\u0433\u0438\u044e, \u0432\u0441\u0451 \u0436\u0435 \u043d\u0435 \u0431\u0435\u0441\u043a\u043e\u043d\u0435\u0447\u0435\u043d. \u0423 \u043d\u0435\u0433\u043e \u0435\u0441\u0442\u044c:<\/p>\n<ul>\n<li>\n<p><strong>\u041b\u0438\u043c\u0438\u0442\u044b \u043f\u043e \u0447\u0438\u0441\u043b\u0443 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0432 \u043c\u0438\u043d\u0443\u0442\u0443 (TPS)<\/strong> \u043d\u0430 \u043a\u043e\u043d\u043a\u0440\u0435\u0442\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c \u2014 \u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0441\u0442\u0430\u0442\u044c \u0443\u0437\u043a\u0438\u043c \u0433\u043e\u0440\u043b\u044b\u0448\u043a\u043e\u043c \u043f\u0440\u0438 \u043c\u0430\u0441\u0441\u043e\u0432\u043e\u0439 \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0435;<\/p>\n<\/li>\n<li>\n<p><strong>\u041b\u0438\u043c\u0438\u0442\u044b \u043f\u043e \u0442\u043e\u043a\u0435\u043d\u0430\u043c<\/strong>: \u043a\u0430\u043a \u0432\u0445\u043e\u0434\u043d\u044b\u043c (prompt + media), \u0442\u0430\u043a \u0438 \u0432\u044b\u0445\u043e\u0434\u043d\u044b\u043c (\u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044f \u043e\u0442\u0432\u0435\u0442\u0430). \u0423 Sonnet, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, ~200k \u0442\u043e\u043a\u0435\u043d\u043e\u0432 \u043d\u0430 \u0441\u0443\u0442\u043a\u0438 \u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u043d\u0430 \u0430\u043a\u043a\u0430\u0443\u043d\u0442 (\u043c\u043e\u0436\u0435\u0442 \u0432\u0430\u0440\u044c\u0438\u0440\u043e\u0432\u0430\u0442\u044c\u0441\u044f).<\/p>\n<\/li>\n<\/ul>\n<p><strong>\u0420\u0435\u0448\u0435\u043d\u0438\u044f \u0438 \u043e\u0431\u0445\u043e\u0434\u043d\u044b\u0435 \u043f\u0443\u0442\u0438:<\/strong><\/p>\n<ol>\n<li>\n<p><strong>\u0417\u0430\u043f\u0440\u043e\u0441 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f \u043a\u0432\u043e\u0442 \u0447\u0435\u0440\u0435\u0437 Service Quotas<\/strong> \u2014 \u043f\u0435\u0440\u0432\u044b\u0439 \u0438 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0448\u0430\u0433, \u0435\u0441\u043b\u0438 \u0432\u044b \u0432\u0438\u0434\u0438\u0442\u0435 throttling.<\/p>\n<\/li>\n<li>\n<p><strong>\u041a\u0440\u043e\u0441\u0441-\u0440\u0435\u0433\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0438\u043d\u0444\u0435\u0440\u0435\u043d\u0441 (inference profiles)<\/strong> \u2014 \u0444\u0438\u0447\u0430, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u0430\u043c \u0432 \u0441\u0432\u043e\u0451\u043c \u0440\u0435\u0433\u0438\u043e\u043d\u0435 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>eu-central-1<\/code>) \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043c\u043e\u0434\u0435\u043b\u044c, \u0440\u0430\u0437\u043c\u0435\u0449\u0451\u043d\u043d\u0443\u044e \u0432 \u0434\u0440\u0443\u0433\u043e\u043c \u0440\u0435\u0433\u0438\u043e\u043d\u0435, \u0433\u0434\u0435 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u0430 \u043d\u0443\u0436\u043d\u0430\u044f \u043a\u0432\u043e\u0442\u0430. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0441\u0438\u043b\u044c\u043d\u043e \u0440\u0430\u0437\u0433\u0440\u0443\u0437\u0438\u0442\u044c \u0442\u043e\u0447\u043a\u0443 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u0438 \u043e\u0431\u043e\u0439\u0442\u0438 \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f.<\/p>\n<p>\u041f\u043e\u0434\u0440\u043e\u0431\u043d\u0435\u0435: <a href=\"https:\/\/docs.aws.amazon.com\/bedrock\/latest\/userguide\/inference-profiles-use.html\" rel=\"noopener noreferrer nofollow\">Using Amazon Bedrock inference profiles<\/a><\/p>\n<p>\u041f\u0440\u0438\u043c\u0435\u0440: \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u043e\u0437\u0434\u0430\u0442\u044c <strong>Bedrock inference profile<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043d\u0430\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0432\u044b\u0437\u043e\u0432 \u043d\u0430 \u043c\u043e\u0434\u0435\u043b\u044c \u0432 <code>us-east-1<\/code>, \u0434\u0430\u0436\u0435 \u0435\u0441\u043b\u0438 \u0432\u0430\u0448\u0430 Lambda \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 <code>eu-central-1<\/code>. \u042d\u0442\u043e \u0434\u0430\u0451\u0442 \u0431\u043e\u043b\u044c\u0448\u0435 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u0438 \u0438 \u043f\u043e\u0432\u044b\u0448\u0430\u0435\u0442 \u0443\u0441\u0442\u043e\u0439\u0447\u0438\u0432\u043e\u0441\u0442\u044c \u043f\u043e\u0434 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u043e\u0439.<\/p>\n<\/li>\n<li>\n<p><strong>Rate Limiting + \u043e\u0447\u0435\u0440\u0435\u0434\u044c<\/strong> \u2014 \u0435\u0441\u043b\u0438 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0430 \u0441\u043b\u0438\u0448\u043a\u043e\u043c \u0432\u0435\u043b\u0438\u043a\u0430, \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u043b\u0438\u0431\u043e \u0437\u0430\u043c\u0435\u0434\u043b\u044f\u0442\u044c \u043f\u043e\u0441\u0442\u0443\u043f\u043b\u0435\u043d\u0438\u0435 \u0437\u0430\u043f\u0440\u043e\u0441\u043e\u0432 \u0447\u0435\u0440\u0435\u0437 throttling \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f, \u043b\u0438\u0431\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u0441 <code>visibility timeout<\/code>, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0442\u044c \u043f\u043e\u0442\u043e\u043a.<\/p>\n<\/li>\n<\/ol>\n<h3>\u041f\u0440\u0438\u043c\u0435\u0440 \u0440\u0430\u0441\u0447\u0435\u0442\u0430 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438 (eu-central-1)<\/h3>\n<p>\u0414\u043e\u043f\u0443\u0441\u0442\u0438\u043c, \u043c\u044b \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c 1000 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043c\u0435\u0441\u044f\u0446:<\/p>\n<div>\n<div class=\"table\">\n<table>\n<tbody>\n<tr>\n<th>\n<p align=\"left\">\u041a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u041a\u043e\u043b-\u0432\u043e<\/p>\n<\/th>\n<th>\n<p align=\"left\">\u041e\u0446\u0435\u043d\u043a\u0430 \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u0438<\/p>\n<\/th>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><strong>Bedrock (Claude Sonnet)<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\">~4000 \u0442\u043e\u043a\u0435\u043d\u043e\u0432 (\u0432\u0445\u043e\u0434 + \u0432\u044b\u0445\u043e\u0434) \u043d\u0430 1 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442<\/p>\n<\/td>\n<td>\n<p align=\"left\">~$0.036 \u00d7 1000 = $36.00<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><strong>Lambda (Invoke + Save)<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\">\u0434\u043e 6 \u0441\u0435\u043a \u00d7 1000 \u0432\u044b\u0437\u043e\u0432\u043e\u0432<\/p>\n<\/td>\n<td>\n<p align=\"left\">~$0.10<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><strong>SQS<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\">1000 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439<\/p>\n<\/td>\n<td>\n<p align=\"left\">~$0.01 (\u0438\u043b\u0438 \u0432 \u043f\u0440\u0435\u0434\u0435\u043b\u0430\u0445 Free Tier)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><strong>DynamoDB<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\">1000 \u0437\u0430\u043f\u0438\u0441\u0435\u0439<\/p>\n<\/td>\n<td>\n<p align=\"left\">&lt;$0.01 (On-Demand)<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><strong>S3<\/strong> (\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u0435 + \u0437\u0430\u043f\u0440\u043e\u0441\u044b)<\/p>\n<\/td>\n<td>\n<p align=\"left\">~2 \u0413\u0411 + \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0438<\/p>\n<\/td>\n<td>\n<p align=\"left\">~$0.05<\/p>\n<\/td>\n<\/tr>\n<tr>\n<td>\n<p align=\"left\"><strong>\u0418\u0442\u043e\u0433\u043e<\/strong><\/p>\n<\/td>\n<td>\n<p align=\"left\">\n<\/td>\n<td>\n<p align=\"left\"><strong>~$36.16 \/ \u043c\u0435\u0441\u044f\u0446<\/strong><\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>\u0415\u0441\u043b\u0438 \u0437\u0430\u043c\u0435\u043d\u0438\u0442\u044c Sonnet \u043d\u0430 <strong>Claude Haiku<\/strong>, \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u043c\u043e\u0436\u0435\u0442 \u0443\u043f\u0430\u0441\u0442\u044c \u0434\u043e <strong>$10\u201312<\/strong> \u0437\u0430 \u0442\u043e\u0442 \u0436\u0435 \u043e\u0431\u044a\u0451\u043c (\u043d\u043e \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0447\u0443\u0442\u044c \u043d\u0438\u0436\u0435). \u0422\u0430\u043a\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c batch-\u0438\u043d\u0444\u0435\u0440\u0435\u043d\u0441 \u0438\u043b\u0438 \u043a\u043e\u043c\u0431\u0438\u043d\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b.<\/p>\n<h3>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h3>\n<p>\u041c\u044b \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u043b\u0438 \u043f\u043e\u043b\u043d\u043e\u0444\u0443\u043d\u043a\u0446\u0438\u043e\u043d\u0430\u043b\u044c\u043d\u044b\u0439 serverless-\u0441\u0435\u0440\u0432\u0438\u0441 \u0434\u043b\u044f OCR \u043d\u0430 \u0431\u0430\u0437\u0435 Amazon Bedrock. \u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0430\u0441\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0439, \u043d\u0430\u0434\u0451\u0436\u043d\u043e\u0439 \u0438 \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0439. \u0412\u043c\u0435\u0441\u0442\u043e \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u043e\u043d\u043d\u043e\u0433\u043e OCR \u043c\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c LLM, \u0447\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043d\u0435 \u043f\u0440\u043e\u0441\u0442\u043e &#171;\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0442\u044c \u0442\u0435\u043a\u0441\u0442&#187;, \u0430 \u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u043e \u0433\u0438\u0431\u043a\u043e, \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u043d\u043e, \u0441 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c\u044e \u0443\u0442\u043e\u0447\u043d\u044f\u0442\u044c, \u0440\u0435\u0437\u044e\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0438\u043b\u0438 \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0443\u0436\u043d\u044b\u0435 \u043f\u043e\u043b\u044f.<\/p>\n<p>\u0424\u0438\u0448\u043a\u0438 \u043f\u043e\u0434\u0445\u043e\u0434\u0430:<\/p>\n<ul>\n<li>\n<p>\u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0435 \u0437\u0430\u0442\u0440\u0430\u0442\u044b \u043d\u0430 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u043a\u0443 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b<\/p>\n<\/li>\n<li>\n<p>\u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e\u0441\u0442\u044c &#171;\u0438\u0437 \u043a\u043e\u0440\u043e\u0431\u043a\u0438&#187;<\/p>\n<\/li>\n<li>\n<p>\u043f\u043e\u043d\u044f\u0442\u043d\u0430\u044f \u0441\u0445\u0435\u043c\u0430 \u0440\u0430\u0431\u043e\u0442\u044b, \u043b\u0435\u0433\u043a\u043e \u0440\u0430\u0441\u0448\u0438\u0440\u044f\u0435\u043c\u0430\u044f \u043f\u043e\u0434 \u043d\u043e\u0432\u044b\u0435 \u0437\u0430\u0434\u0430\u0447\u0438<\/p>\n<\/li>\n<li>\n<p>\u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0434\u043e\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438, A\/B \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u043c\u043e\u0434\u0435\u043b\u0435\u0439 \u0438 \u0444\u0430\u043d-\u0430\u0443\u0442\u0430 \u0447\u0435\u0440\u0435\u0437 SNS<\/p>\n<\/li>\n<\/ul>\n<hr\/>\n<blockquote>\n<p>\u26a0\ufe0f <strong>\u0412\u0430\u0436\u043d\u043e:<\/strong> \u0412 \u0441\u0432\u043e\u0435\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0438 \u044f \u043d\u0435 \u043f\u0440\u0435\u0442\u0435\u043d\u0434\u0443\u044e \u043d\u0430 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u044c. \u0422\u0430\u043a\u0436\u0435, \u043a\u043e\u0434 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435 <strong>\u0430\u0434\u0430\u043f\u0442\u0438\u0440\u043e\u0432\u0430\u043d \u0434\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438<\/strong> \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u044b \u0438 \u0443\u043f\u0440\u043e\u0449\u0451\u043d \u0434\u043b\u044f \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u0438. \u041d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0444\u0440\u0430\u0433\u043c\u0435\u043d\u0442\u044b \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u043d\u0435 \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e production-ready \u2014 \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0442\u0438\u043f\u044b \u043e\u0448\u0438\u0431\u043e\u043a Bedrock, \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f, retry-\u043b\u043e\u0433\u0438\u043a\u0430, \u0432\u0430\u043b\u0438\u0434\u0430\u0446\u0438\u044f \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0438 \u043f\u0440.<\/p>\n<p>\u0412 \u043f\u0440\u043e\u0434\u0430\u043a\u0448\u0435\u043d\u0435 \u043e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e:<\/p>\n<ul>\n<li>\n<p>\u0443\u0431\u0435\u0434\u0438\u0442\u0435\u0441\u044c \u0432 \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e\u0439 \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0435 IAM-\u0440\u043e\u043b\u0435\u0439,<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e\u0432\u0435\u0440\u044c\u0442\u0435 \u043b\u0438\u043c\u0438\u0442\u044b \u0438 \u043a\u0432\u043e\u0442\u044b \u0432 Bedrock, Lambda \u0438 SQS,<\/p>\n<\/li>\n<li>\n<p>\u0434\u043e\u0431\u0430\u0432\u044c\u0442\u0435 retry\/timeout\/\u043b\u043e\u0433\u0433\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435,<\/p>\n<\/li>\n<li>\n<p>\u043f\u0440\u043e\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0439\u0442\u0435 \u043a\u043e\u0434 \u043f\u043e\u0434 \u0440\u0435\u0430\u043b\u044c\u043d\u0443\u044e \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443.<\/p>\n<\/li>\n<\/ul>\n<\/blockquote>\n<blockquote>\n<p>\u0415\u0441\u043b\u0438 \u0431\u0443\u0434\u0435\u0442\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u0434 \u043a\u0430\u043a \u043e\u0441\u043d\u043e\u0432\u0443 \u2014 <strong>\u0442\u0435\u0441\u0442\u0438\u0440\u0443\u0439\u0442\u0435 \u0438 \u0434\u043e\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0434 \u0441\u0432\u043e\u0439 \u043f\u0440\u043e\u0435\u043a\u0442<\/strong>. \u0412\u0441\u0451, \u0447\u0442\u043e \u0437\u0434\u0435\u0441\u044c \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e, \u043d\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0447\u0443\u0432\u0441\u0442\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438 \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u043b\u0435\u043d\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0432 \u043e\u0437\u043d\u0430\u043a\u043e\u043c\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0446\u0435\u043b\u044f\u0445.<\/p>\n<\/blockquote>\n<hr\/>\n<details class=\"spoiler\">\n<summary>Bonus: Step Functions<\/summary>\n<div class=\"spoiler__content\">\n<p>\u0412\u0441\u0435 \u0432\u044b\u0448\u0435\u043f\u0435\u0440\u0435\u0447\u0438\u0441\u043b\u0435\u043d\u043d\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432 \u043e\u0434\u043d\u043e\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 State Machine:<\/p>\n<figure class=\"full-width\"><img decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ed1\/e43\/5ea\/ed1e435ea633a85dbf66b893740f7790.png\" width=\"564\" height=\"648\" sizes=\"auto, (max-width: 780px) 100vw, 50vw\" srcset=\"https:\/\/habrastorage.org\/r\/w780\/getpro\/habr\/upload_files\/ed1\/e43\/5ea\/ed1e435ea633a85dbf66b893740f7790.png 780w,&#10;       https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ed1\/e43\/5ea\/ed1e435ea633a85dbf66b893740f7790.png 781w\" loading=\"lazy\" decode=\"async\"\/><\/figure>\n<pre><code class=\"yaml\">Comment: &gt;-   A Bedrock OCR state machine that invokes a Bedrock model and saves the   results to S3 and DynamoDB. StartAt: Prepare Bedrock payload States:   Prepare Bedrock payload:     Type: Pass     Next: Bedrock InvokeModel   Bedrock InvokeModel:     Type: Task     Resource: arn:aws:states:::bedrock:invokeModel     Parameters: {}     Next: Save to s3   Save to s3:     Type: Task     Resource: arn:aws:states:::lambda:invoke     OutputPath: $.Payload     Parameters:       Payload.$: $     Retry:       - ErrorEquals:           - Lambda.ServiceException           - Lambda.AWSLambdaException           - Lambda.SdkClientException           - Lambda.TooManyRequestsException         IntervalSeconds: 1         MaxAttempts: 3         BackoffRate: 2         JitterStrategy: FULL     Next: Parallel State   Parallel State:     Comment: &gt;-       A Parallel state can be used to create parallel branches of execution in       your state machine.     Type: Parallel     Branches:       - StartAt: DynamoDB PutItem         States:           DynamoDB PutItem:             Type: Task             Resource: arn:aws:states:::dynamodb:putItem             Parameters:               TableName: MyDynamoDBTable               Item:                 Column:                   S: MyEntry             End: true       - StartAt: Do whatever else         States:           Do whatever else:             Type: Pass             End: true     End: true <\/code><\/pre>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/906738\/\"> https:\/\/habr.com\/ru\/articles\/906738\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041d\u0435\u0434\u0430\u0432\u043d\u043e \u043f\u0435\u0440\u0435\u0434\u043e \u043c\u043d\u043e\u0439 \u0432\u0441\u0442\u0430\u043b\u0430 \u0437\u0430\u0434\u0430\u0447\u0430: \u043e\u0440\u0433\u0430\u043d\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043f\u0440\u043e\u0441\u0442\u043e\u0435 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0435 \u0442\u0435\u043a\u0441\u0442\u0430 \u0438\u0437 \u0437\u0430\u0433\u0440\u0443\u0436\u0435\u043d\u043d\u044b\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 (\u0441\u043a\u0430\u043d\u044b PDF, \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u044f PNG\/JPG) \u043d\u0430 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u0445 AWS. \u041a\u043b\u0430\u0441\u0441\u0438\u0447\u0435\u0441\u043a\u0438\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u2013 \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0441\u0435\u0440\u0432\u0438\u0441\u043e\u043c <strong>Amazon Textract<\/strong> \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0437\u0430\u043f\u0443\u0441\u0442\u0438\u0442\u044c <strong>Tesseract<\/strong> \u0432\u043d\u0443\u0442\u0440\u0438 Lambda. \u041e\u0434\u043d\u0430\u043a\u043e, \u043f\u043e\u0434\u0445\u043e\u0434 \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c <strong>Amazon Bedrock<\/strong> \u043c\u043d\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043b\u0441\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u0440\u0438\u0432\u043b\u0435\u043a\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u043c \u0438 \u043d\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0449\u0438\u043c &#171;\u0442\u0430\u043d\u0446\u0435\u0432 \u0441 \u0431\u0443\u0431\u043d\u043e\u043c&#187; \u0432\u043e\u043a\u0440\u0443\u0433 \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u043e\u0442\u0432\u0435\u0442\u0430 Textract.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u043f\u043e\u0441\u0442\u0435 \u044f \u0440\u0430\u0441\u0441\u043a\u0430\u0436\u0443, \u043a\u0430\u043a \u043d\u0430 \u043f\u0440\u0430\u043a\u0442\u0438\u043a\u0435 \u0437\u0430 \u043f\u0430\u0440\u0443 \u0447\u0430\u0441\u043e\u0432 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043b \u0431\u0435\u0437\u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0439 (serverless) OCR-\u0441\u0435\u0440\u0432\u0438\u0441 \u043d\u0430 AWS, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f <strong>AWS Lambda<\/strong> \u0438 \u043c\u043e\u0434\u0435\u043b\u044c \u0438\u0437 <strong>Amazon Bedrock<\/strong> \u0434\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u0447\u0435\u043d\u0438\u044f \u0442\u0435\u043a\u0441\u0442\u0430. \u0421\u0442\u0430\u0442\u044c\u044f \u043e\u0440\u0438\u0435\u043d\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0430 \u043d\u0430 \u043e\u043f\u044b\u0442\u043d\u044b\u0445 AWS-\u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u043e\u0440\u043e\u0432, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043c\u044b \u0443\u0433\u043b\u0443\u0431\u0438\u043c\u0441\u044f \u0432 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443, \u043f\u043e\u043a\u0430\u0436\u0443 \u043a\u043e\u0434 (Terraform \u0434\u043b\u044f \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u044b \u0438 Python \u0434\u043b\u044f Lambda), \u043e\u0431\u0441\u0443\u0434\u0438\u043c \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435, \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u044f \u0438 \u043f\u0440\u0438\u043a\u0438\u043d\u0435\u043c \u0441\u0442\u043e\u0438\u043c\u043e\u0441\u0442\u044c \u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0432 \u0440\u0435\u0433\u0438\u043e\u043d\u0435 <strong>eu-central-1 (\u0424\u0440\u0430\u043d\u043a\u0444\u0443\u0440\u0442)<\/strong>. \u041f\u043e\u0435\u0445\u0430\u043b\u0438!<\/p>\n<h3>\u0410\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u0440\u0435\u0448\u0435\u043d\u0438\u044f<\/h3>\n<p>\u041f\u0435\u0440\u0432\u043e\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u0430\u044f \u0438\u0434\u0435\u044f \u0437\u0430\u043a\u043b\u044e\u0447\u0430\u043b\u0430\u0441\u044c \u0432 \u0442\u043e\u043c, \u0447\u0442\u043e\u0431\u044b \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c Lambda-\u0444\u0443\u043d\u043a\u0446\u0438\u044e \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0447\u0435\u0440\u0435\u0437 S3 Event Notification \u043f\u0440\u0438 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0435 \u043d\u043e\u0432\u043e\u0433\u043e \u043e\u0431\u044a\u0435\u043a\u0442\u0430. \u041d\u043e \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0441\u0442\u0430\u043b\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e: <strong>\u044d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u043f\u0440\u0438\u0432\u0435\u0441\u0442\u0438 \u043a \u0441\u0435\u0440\u044c\u0451\u0437\u043d\u044b\u043c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430\u043c \u0441 \u0442\u0440\u043e\u0442\u0442\u043b\u0438\u043d\u0433\u043e\u043c \u0438 \u043f\u0440\u0435\u0432\u044b\u0448\u0435\u043d\u0438\u0435\u043c \u043b\u0438\u043c\u0438\u0442\u0430 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 Lambda (concurrent executions)<\/strong> \u043d\u0430 \u0431\u043e\u043b\u044c\u0448\u043e\u043c \u043e\u0431\u044a\u0435\u043c\u0435 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<p>\u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u0438\u043c \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u044e: \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u043f\u0430\u0447\u043a\u0443 \u0438\u0437 500 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 S3. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0432\u044b\u0437\u0432\u0430\u0442\u044c 500 \u043f\u0430\u0440\u0430\u043b\u043b\u0435\u043b\u044c\u043d\u044b\u0445 \u0432\u044b\u0437\u043e\u0432\u043e\u0432 Lambda-\u0444\u0443\u043d\u043a\u0446\u0438\u0438. \u0415\u0441\u043b\u0438 \u0444\u0443\u043d\u043a\u0446\u0438\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0442\u044f\u0436\u0451\u043b\u0430\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0434\u0435\u043b\u0430\u0435\u0442 \u0432\u044b\u0437\u043e\u0432 \u043a Bedrock \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u043f\u043e 5-10 \u0441\u0435\u043a\u0443\u043d\u0434), \u0442\u043e \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u0441\u0442\u0440\u043e \u0443\u043f\u0435\u0440\u0435\u0442\u044c\u0441\u044f \u0432 \u043b\u0438\u043c\u0438\u0442 \u043d\u0430 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 \u0432\u044b\u0437\u043e\u0432\u044b (\u043f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e 1000 \u043d\u0430 \u0430\u043a\u043a\u0430\u0443\u043d\u0442). \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u043f\u0440\u0438 \u0440\u0435\u0437\u043a\u043e\u043c \u0432\u0441\u043f\u043b\u0435\u0441\u043a\u0435 \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u0442\u0440\u0430\u0444\u0438\u043a\u0430 S3 \u043d\u0435 \u0438\u043c\u0435\u0435\u0442 \u0432\u0441\u0442\u0440\u043e\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c\u0430 <strong>\u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u0441\u043a\u043e\u0440\u043e\u0441\u0442\u0438 (rate limiting)<\/strong> \u0434\u043b\u044f \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u2013 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u043b\u0435\u0442\u044f\u0442 \u0431\u0435\u0437 \u0443\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f.<\/p>\n<h4>\u041a\u0430\u043a \u044f \u0440\u0435\u0448\u0438\u043b \u044d\u0442\u0443 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443:<\/h4>\n<p>\u042f \u0437\u0430\u043c\u0435\u043d\u0438\u043b \u043f\u0440\u044f\u043c\u043e\u0439 \u0432\u044b\u0437\u043e\u0432 Lambda \u0441 S3 \u043d\u0430 <strong>\u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u0431\u0443\u0444\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u044e \u0447\u0435\u0440\u0435\u0437 EventBridge + SQS + SNS<\/strong>. \u0412\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u044d\u0442\u043e \u0442\u0430\u043a:<\/p>\n<ol>\n<li>\n<p><strong>\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442 \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442\u0441\u044f \u0432 S3<\/strong> \u2013 \u044d\u0442\u043e \u0442\u0440\u0438\u0433\u0433\u0435\u0440\u0438\u0442 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0432 <strong>EventBridge<\/strong>. \u041c\u043d\u043e\u0433\u0438\u0435 \u043d\u0435 \u0437\u043d\u0430\u044e\u0442, \u043d\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u044f S3 \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u043e\u044f\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0432 <strong>default event bus<\/strong>. \u041c\u044b \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c <strong>EventBridge Rule<\/strong>, \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0444\u0438\u043b\u044c\u0442\u0440\u0443\u0435\u0442 \u043d\u0443\u0436\u043d\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, <code>PutObject<\/code> \u0432 \u043d\u0443\u0436\u043d\u043e\u043c \u0431\u0430\u043a\u0435\u0442\u0435 \u0441 \u043d\u0443\u0436\u043d\u044b\u043c \u043f\u0440\u0435\u0444\u0438\u043a\u0441\u043e\u043c <code>uploads\/<\/code>).<\/p>\n<\/li>\n<li>\n<p>\u042d\u0442\u043e \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u043c\u044b <strong>\u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0432 SQS<\/strong> \u0438 \u0434\u0430\u043b\u0435\u0435 \u0443\u0436\u0435 \u0432 \u0442\u043e\u043f\u0438\u043a <strong>SNS<\/strong>:<\/p>\n<ul>\n<li>\n<p>\u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0434\u043d\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432 <strong>SQS<\/strong> \u2013 \u0434\u043b\u044f \u0431\u0443\u0444\u0435\u0440\u0438\u0437\u0430\u0446\u0438\u0438 \u0438 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f \u043f\u043e\u0442\u043e\u043a\u0430;<\/p>\n<\/li>\n<li>\n<p>\u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 <strong>Lambda-\u0444\u0443\u043d\u043a\u0446\u0438\u044e<\/strong>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0434\u043e\u0441\u0442\u0430\u0451\u0442 \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0438\u0437 \u0442\u043e\u043f\u0438\u043a\u0430 SNS \u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 OCR-\u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443.<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>\u0422\u0430\u043a\u043e\u0439 \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0440\u0435\u0448\u0430\u0435\u0442 \u0441\u0440\u0430\u0437\u0443 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0437\u0430\u0434\u0430\u0447:<\/p>\n<ul>\n<li>\n<p>\u041f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 <strong>\u043e\u0442\u0434\u0435\u043b\u0438\u0442\u044c<\/strong> \u043c\u043e\u043c\u0435\u043d\u0442 \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0444\u0430\u0439\u043b\u0430 \u0438 \u043d\u0430\u0447\u0430\u043b\u043e \u0435\u0433\u043e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438.<\/p>\n<\/li>\n<li>\n<p>\u0427\u0435\u0440\u0435\u0437 <strong>SQS<\/strong> \u043c\u043e\u0436\u043d\u043e \u043b\u0435\u0433\u043a\u043e \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443 (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0435\u0441\u043b\u0438 \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0440\u0430\u0441\u0442\u0451\u0442 \u2013 \u043c\u043e\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0435\u0449\u0451 \u043e\u0434\u043d\u0443 Lambda \u0438\u043b\u0438 \u043a\u043e\u043d\u0442\u0435\u0439\u043d\u0435\u0440).<\/p>\n<\/li>\n<li>\n<p>\u041c\u043e\u0436\u043d\u043e \u0434\u0435\u043b\u0430\u0442\u044c <strong>\u0434\u0435\u0434\u0443\u043f\u043b\u0438\u043a\u0430\u0446\u0438\u044e<\/strong>, <strong>\u0440\u0435\u0442\u0440\u0430\u0438<\/strong>, \u0438\u043b\u0438 \u0434\u0430\u0436\u0435 \u0444\u0438\u043b\u044c\u0442\u0440\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0435 \u0441\u043e\u0431\u044b\u0442\u0438\u044f \u0447\u0435\u0440\u0435\u0437 EventBridge.<\/p>\n<\/li>\n<\/ul>\n<h4>\u0412\u0442\u043e\u0440\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430: \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432 SQS<\/h4>\n<p>\u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u044f \u0445\u043e\u0442\u0435\u043b, \u0447\u0442\u043e\u0431\u044b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 OCR \u043f\u043e\u043f\u0430\u0434\u0430\u043b \u0441\u0440\u0430\u0437\u0443 \u0432\u043e \u0432\u0442\u043e\u0440\u0443\u044e <strong>SQS<\/strong> \u0438\u0437 \u043f\u0435\u0440\u0432\u043e\u0439 Lambda. \u041d\u043e \u0442\u0443\u0442 \u043c\u044b \u043d\u0430\u0442\u0430\u043b\u043a\u0438\u0432\u0430\u0435\u043c\u0441\u044f \u043d\u0430 \u0441\u0443\u0440\u043e\u0432\u043e\u0435 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435: <strong>\u0440\u0430\u0437\u043c\u0435\u0440 \u043e\u0434\u043d\u043e\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432 SQS \u2014 \u043d\u0435 \u0431\u043e\u043b\u0435\u0435 256 \u041a\u0411<\/strong>. \u042d\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u043a\u0440\u0438\u0442\u0438\u0447\u043d\u044b\u043c, \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e \u0435\u0441\u043b\u0438 \u043c\u043e\u0434\u0435\u043b\u044c Bedrock \u0432\u0435\u0440\u043d\u0451\u0442 \u0434\u043b\u0438\u043d\u043d\u044b\u0439 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u043d\u043d\u044b\u0439 \u0442\u0435\u043a\u0441\u0442 \u0438\u043b\u0438 structured output (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, JSON \u0441 \u043a\u0443\u0447\u0435\u0439 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 PDF-\u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u0430).<\/p>\n<h4>\u041a\u0430\u043a \u043e\u0431\u043e\u0439\u0442\u0438 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435:<\/h4>\n<p>\u042f \u0438\u0437\u043c\u0435\u043d\u0438\u043b \u043f\u0430\u0442\u0442\u0435\u0440\u043d \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c:<\/p>\n<ul>\n<li>\n<p><strong>\u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0440\u0430\u0431\u043e\u0442\u044b Bedrock \u043a\u043b\u0430\u0434\u0451\u0442\u0441\u044f \u0432 S3<\/strong> (\u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0432 \u0431\u0430\u043a\u0435\u0442 <code>ocr-results-bucket\/uuid.json<\/code>).<\/p>\n<\/li>\n<li>\n<p>\u0412 SQS \u0438\u0434\u0451\u0442 <strong>\u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0441\u044b\u043b\u043a\u0430<\/strong> \u043d\u0430 \u0444\u0430\u0439\u043b \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430: <code>{ \"resultKey\": \"ocr-results\/123.json\", \"sourceKey\": \"uploads\/filename.png\" }<\/code>.<\/p>\n<\/li>\n<li>\n<p>Lambda-\u043f\u043e\u0434\u043f\u0438\u0441\u0447\u0438\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0447\u0438\u0442\u0430\u0435\u0442 \u0438\u0437 \u043e\u0447\u0435\u0440\u0435\u0434\u0438, \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u043e\u0434\u0442\u044f\u0433\u0438\u0432\u0430\u0435\u0442 JSON \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0438\u0437 S3 \u0438 \u043f\u0438\u0448\u0435\u0442 \u043d\u0443\u0436\u043d\u044b\u0435 \u043f\u043e\u043b\u044f \u0432 DynamoDB.<\/p>\n<\/li>\n<\/ul>\n<p>\u042d\u0442\u043e \u043d\u0430\u0434\u0451\u0436\u043d\u043e, \u043c\u0430\u0441\u0448\u0442\u0430\u0431\u0438\u0440\u0443\u0435\u043c\u043e \u0438 \u0443\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0432 \u043b\u0438\u043c\u0438\u0442\u044b. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435, \u0435\u0441\u043b\u0438 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u0440\u0443\u0447\u043d\u044b\u0435 \u0440\u0435\u0442\u0440\u0430\u0438 \u0438\u043b\u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u043a\u0430 \u043e\u0448\u0438\u0431\u043e\u043a, \u0443\u0434\u043e\u0431\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0435\u0440\u0435\u0447\u0438\u0442\u0430\u0442\u044c S3-\u0444\u0430\u0439\u043b.<\/p>\n<p>\u0418\u0442\u043e\u0433\u043e\u0432\u0430\u044f \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430:<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0437\u0430\u0433\u0440\u0443\u0436\u0430\u0435\u0442 \u0444\u0430\u0439\u043b \u0432 S3 \u0432 \u043f\u0430\u043f\u043a\u0443 <code>uploads\/<\/code><\/p>\n<\/li>\n<li>\n<p>EventBridge \u043b\u043e\u0432\u0438\u0442 <code>PutObject<\/code> \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0435\u0433\u043e \u0432 SNS topic:<\/p>\n<ul>\n<li>\n<p>\u0432 \u043e\u0447\u0435\u0440\u0435\u0434\u044c SQS (\u0431\u0443\u0444\u0435\u0440);<\/p>\n<\/li>\n<li>\n<p>\u0438 \u043e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442 Lambda <code>InvokeBedrock<\/code> (\u0447\u0435\u0440\u0435\u0437 SNS);<\/p>\n<\/li>\n<\/ul>\n<\/li>\n<li>\n<p>Lambda \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u043f\u0443\u0442\u044c \u043a \u0444\u0430\u0439\u043b\u0443, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 Bedrock, \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 OCR \u0432 S3 (\u0432 <code>ocr-results\/<\/code>) \u0438 \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432 SQS c \u0441\u0441\u044b\u043b\u043a\u043e\u0439 \u043d\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442.<\/p>\n<\/li>\n<li>\n<p>\u0412\u0442\u043e\u0440\u0430\u044f Lambda <code>SaveToDB<\/code> \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u0442 \u043e\u0447\u0435\u0440\u0435\u0434\u044c, \u043f\u043e\u0434\u0442\u044f\u0433\u0438\u0432\u0430\u0435\u0442 JSON \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c \u0438\u0437 S3 \u0438 \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u0442 \u0432 DynamoDB \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u044d\u0442\u043e\u0442 \u043e\u0431\u044a\u0435\u043a\u0442. \u042d\u0442\u043e \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0438\u0437\u0431\u0435\u0436\u0430\u0442\u044c \u043f\u0440\u0435\u0432\u044b\u0448\u0435\u043d\u0438\u044f \u043b\u0438\u043c\u0438\u0442\u043e\u0432 \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 DynamoDB \u0438 \u0441\u043d\u0438\u0437\u0438\u0442\u044c \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0443 \u043f\u0440\u0438 \u0447\u0442\u0435\u043d\u0438\u0438, \u0432\u0435\u0434\u044c \u043f\u043e\u043b\u043d\u044b\u0439 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u043f\u043e \u0441\u0441\u044b\u043b\u043a\u0435 \u0438\u0437 S3.<\/p>\n<\/li>\n<\/ol>\n<p>\u0412\u0441\u0451 \u2014 \u043c\u044b \u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u043b\u0438 \u0440\u0438\u0441\u043a\u0438 \u0442\u0440\u043e\u0442\u0442\u043b\u0438\u043d\u0433\u0430, \u0441\u043e\u0431\u043b\u044e\u043b\u0438 \u043b\u0438\u043c\u0438\u0442\u044b SQS \u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0438\u043b\u0438 serverless-\u043f\u043e\u0434\u0445\u043e\u0434.<\/p>\n<h3>Terraform \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u044f<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c, \u043a\u043e\u0433\u0434\u0430 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0430 \u043f\u0440\u043e\u0440\u0430\u0431\u043e\u0442\u0430\u043d\u0430, \u043c\u043e\u0436\u043d\u043e \u043e\u043f\u0438\u0441\u0430\u0442\u044c \u0432\u0441\u0451 \u044d\u0442\u043e \u0432 Terraform. \u041d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f:<\/p>\n<ul>\n<li>\n<p>S3-\u0431\u0430\u043a\u0435\u0442 \u0434\u043b\u044f \u0437\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0445 \u0434\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u043e\u0432<\/p>\n<\/li>\n<li>\n<p>EventBridge Rule<\/p>\n<\/li>\n<li>\n<p>SNS-\u0442\u043e\u043f\u0438\u043a \u0438 \u043f\u043e\u0434\u043f\u0438\u0441\u043a\u0438 (\u043d\u0430 Lambda \u0438 SQS)<\/p>\n<\/li>\n<li>\n<p>\u041e\u0447\u0435\u0440\u0435\u0434\u044c SQS<\/p>\n<\/li>\n<li>\n<p>Lambda-\u0444\u0443\u043d\u043a\u0446\u0438\u0438 (InvokeBedrock \u0438 SaveToDB)<\/p>\n<\/li>\n<li>\n<p>IAM \u0440\u043e\u043b\u0438 \u0438 \u043f\u043e\u043b\u0438\u0442\u0438\u043a\u0438 \u0434\u043b\u044f Lambda<\/p>\n<\/li>\n<li>\n<p>DynamoDB \u0442\u0430\u0431\u043b\u0438\u0446\u0430<\/p>\n<\/li>\n<li>\n<p>S3-\u0431\u0430\u043a\u0435\u0442 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 OCR<\/p>\n<\/li>\n<\/ul>\n<p>\u041a\u043e\u0434 \u043d\u0438\u0436\u0435 \u0440\u0430\u0437\u0432\u043e\u0440\u0430\u0447\u0438\u0432\u0430\u0435\u0442 \u0438\u043d\u0444\u0440\u0430\u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u043f\u043e\u0434 \u043d\u0430\u0448\u0443 \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0443 \u0438 \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442:<\/p>\n<ul>\n<li>\n<p>\u0431\u0435\u0437\u043e\u043f\u0430\u0441\u043d\u0443\u044e \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0443 \u0434\u0430\u043d\u043d\u044b\u0445 \u0447\u0435\u0440\u0435\u0437 SQS<\/p>\n<\/li>\n<li>\n<p>\u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u0435 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0432 S3<\/p>\n<\/li>\n<li>\n<p>\u0444\u0430\u043d-\u0430\u0443\u0442 \u0447\u0435\u0440\u0435\u0437 SNS<\/p>\n<\/li>\n<li>\n<p>\u043c\u0438\u043d\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u044e \u0440\u0438\u0441\u043a\u043e\u0432 \u0442\u0440\u043e\u0442\u0442\u043b\u0438\u043d\u0433\u0430<\/p>\n<\/li>\n<\/ul>\n<details class=\"spoiler\">\n<summary>main.tf<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"vhdl\">provider \"aws\" {   region = \"eu-central-1\" }  # S3 buckets resource \"aws_s3_bucket\" \"uploads\" {   bucket = \"ocr-input-documents\" }  resource \"aws_s3_bucket\" \"results\" {   bucket = \"ocr-processed-results\" }  # DynamoDB \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u043c\u0435\u0442\u0430\u0434\u0430\u043d\u043d\u044b\u0445 (\u043a\u043b\u044e\u0447\u0435\u0439) resource \"aws_dynamodb_table\" \"ocr_index\" {   name         = \"OCRResultsIndex\"   billing_mode = \"PAY_PER_REQUEST\"   hash_key     = \"Id\"   attribute {     name = \"Id\"     type = \"S\"   } }  # SNS Topic resource \"aws_sns_topic\" \"ocr_topic\" {   name = \"ocr-trigger-topic\" }  # SQS Queue resource \"aws_sqs_queue\" \"ocr_queue\" {   name = \"ocr-processing-queue\" }  # \u041f\u043e\u0434\u043f\u0438\u0441\u043a\u0430 SQS \u043a SNS resource \"aws_sns_topic_subscription\" \"sqs_sub\" {   topic_arn = aws_sns_topic.ocr_topic.arn   protocol  = \"sqs\"   endpoint  = aws_sqs_queue.ocr_queue.arn }  # \u041f\u043e\u0434\u043f\u0438\u0441\u043a\u0430 Lambda \u043d\u0430 SNS (InvokeBedrock) resource \"aws_lambda_permission\" \"allow_sns_invoke_lambda\" {   statement_id  = \"AllowExecutionFromSNS\"   action        = \"lambda:InvokeFunction\"   function_name = aws_lambda_function.invoke_bedrock.function_name   principal     = \"sns.amazonaws.com\"   source_arn    = aws_sns_topic.ocr_topic.arn }  resource \"aws_sns_topic_subscription\" \"lambda_sub\" {   topic_arn = aws_sns_topic.ocr_topic.arn   protocol  = \"lambda\"   endpoint  = aws_lambda_function.invoke_bedrock.arn }  # EventBridge Rule: \u043e\u0442\u043b\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c PutObject \u0432 \u0431\u0430\u043a\u0435\u0442\u0435 resource \"aws_cloudwatch_event_rule\" \"s3_put\" {   name        = \"ocr-upload-trigger\"   event_pattern = jsonencode({     \"source\": [\"aws.s3\"],     \"detail-type\": [\"Object Created\"],     \"detail\": {       \"bucket\": {\"name\": [aws_s3_bucket.uploads.bucket]},       \"object\": {\"key\": [{\"prefix\": \"uploads\/\"}]}     }   }) }  # Target \u2014 SNS resource \"aws_cloudwatch_event_target\" \"to_sns\" {   rule      = aws_cloudwatch_event_rule.s3_put.name   target_id = \"SendToSNS\"   arn       = aws_sns_topic.ocr_topic.arn }  resource \"aws_lambda_function\" \"invoke_bedrock\" {   function_name = \"InvokeBedrockOCR\"   role          = aws_iam_role.lambda_role.arn   handler       = \"invoke.lambda_handler\"   runtime       = \"python3.10\"   filename      = \"lambda_invoke.zip\"    environment {     variables = {       RESULT_BUCKET = aws_s3_bucket.results.bucket       QUEUE_URL     = aws_sqs_queue.ocr_queue.id     }   } }  resource \"aws_lambda_function\" \"save_result\" {   function_name = \"SaveOCRToDynamo\"   role          = aws_iam_role.lambda_role.arn   handler       = \"save.lambda_handler\"   runtime       = \"python3.10\"   filename      = \"lambda_save.zip\"    environment {     variables = {       TABLE_NAME    = aws_dynamodb_table.ocr_index.name       RESULT_BUCKET = aws_s3_bucket.results.bucket     }   } }  # \u041f\u0440\u0438\u0432\u044f\u0437\u043a\u0430 \u043e\u0447\u0435\u0440\u0435\u0434\u0438 \u043a \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0441\u043e\u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f resource \"aws_lambda_event_source_mapping\" \"sqs_trigger\" {   event_source_arn = aws_sqs_queue.ocr_queue.arn   function_name    = aws_lambda_function.save_result.arn   batch_size       = 1 }  # IAM Role + Policy resource \"aws_iam_role\" \"lambda_role\" {   name = \"ocr_lambda_role\"   assume_role_policy = jsonencode({     Version = \"2012-10-17\",     Statement = [{       Effect = \"Allow\",       Principal = { Service = \"lambda.amazonaws.com\" },       Action = \"sts:AssumeRole\"     }]   }) }  resource \"aws_iam_role_policy\" \"lambda_policy\" {   name = \"ocr_lambda_inline\"   role = aws_iam_role.lambda_role.id   policy = jsonencode({     Version = \"2012-10-17\",     Statement = [       {         Effect = \"Allow\",         Action = [\"s3:GetObject\", \"s3:PutObject\"],         Resource = [           \"${aws_s3_bucket.uploads.arn}\/*\",           \"${aws_s3_bucket.results.arn}\/*\"         ]       },       {         Effect = \"Allow\",         Action = [\"bedrock:InvokeModel\"],         Resource = \"*\"       },       {         Effect = \"Allow\",         Action = [\"dynamodb:PutItem\"],         Resource = aws_dynamodb_table.ocr_index.arn       },       {         Effect = \"Allow\",         Action = [\"sqs:SendMessage\", \"sqs:ReceiveMessage\", \"sqs:DeleteMessage\"],         Resource = aws_sqs_queue.ocr_queue.arn       },       {         Effect = \"Allow\",         Action = [           \"logs:CreateLogGroup\",           \"logs:CreateLogStream\",           \"logs:PutLogEvents\"         ],         Resource = \"arn:aws:logs:*:*:*\"       }     ]   }) }<\/code><\/pre>\n<\/div>\n<\/details>\n<h3>Lambda-\u0444\u0443\u043d\u043a\u0446\u0438\u044f: \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0430 PDF \u0438 \u0432\u044b\u0437\u043e\u0432 Bedrock<\/h3>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0440\u0430\u0437\u0431\u0435\u0440\u0451\u043c \u043f\u0435\u0440\u0432\u0443\u044e Lambda-\u0444\u0443\u043d\u043a\u0446\u0438\u044e (<code>InvokeBedrock<\/code>), \u043a\u043e\u0442\u043e\u0440\u0430\u044f:<\/p>\n<ol>\n<li>\n<p>\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0443\u0432\u0435\u0434\u043e\u043c\u043b\u0435\u043d\u0438\u0435 \u0438\u0437 SNS \u043e \u043d\u043e\u0432\u043e\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u0435 \u0432 S3<\/p>\n<\/li>\n<li>\n<p>\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u0442, \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0438 \u0444\u0430\u0439\u043b PDF \u0438\u043b\u0438 \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435\u043c<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u044d\u0442\u043e PDF \u2014 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442 \u0435\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435 \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432 Bedrock, \u0442\u0430\u043a \u043a\u0430\u043a \u043c\u043e\u0434\u0435\u043b\u0438 Claude 3 \u0443\u043c\u0435\u044e\u0442 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c PDF-\u0444\u0430\u0439\u043b\u044b \u0431\u0435\u0437 \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e\u0439 \u043a\u043e\u043d\u0432\u0435\u0440\u0442\u0430\u0446\u0438\u0438; \u0435\u0441\u043b\u0438 \u044d\u0442\u043e \u0438\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 (JPEG, PNG), \u043e\u043d\u043e \u043a\u043e\u0434\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u0432 base64 \u0438 \u0442\u0430\u043a\u0436\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442\u0441\u044f \u043c\u043e\u0434\u0435\u043b\u0438<\/p>\n<\/li>\n<li>\n<p>\u0412\u044b\u0437\u044b\u0432\u0430\u0435\u0442 Amazon Bedrock \u0441 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u044b\u043c \u0444\u0430\u0439\u043b\u0430 \u0438 \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u043e\u0442\u0432\u0435\u0442<\/p>\n<\/li>\n<li>\n<p>\u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u0442 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0432 S3 \u0438 \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u0435\u0442 \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043d\u0435\u0433\u043e \u0432 SQS<\/p>\n<\/li>\n<\/ol>\n<details class=\"spoiler\">\n<summary>lambda_invoke_bedrock.py<\/summary>\n<div class=\"spoiler__content\">\n<pre><code class=\"python\">import os import json import base64 import boto3 import mimetypes from urllib.parse import unquote_plus from aws_lambda_powertools import Logger  logger = Logger(service=\"ocr-bedrock\")  s3_client = boto3.client(\"s3\") bedrock_client = boto3.client(\"bedrock-runtime\") sqs_client = boto3.client(\"sqs\")  RESULT_BUCKET = os.environ.get(\"RESULT_BUCKET\") QUEUE_URL =<\/code><\/pre>\n<\/div>\n<\/details>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-458530","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/458530","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=458530"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/458530\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=458530"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=458530"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=458530"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}