Store off-chain data using Amazon Managed Blockchain and Amazon S3: Part 2

海外精选
海外精选的内容汇集了全球优质的亚马逊云科技相关技术内容。同时,内容中提到的“AWS” 是 “Amazon Web Services” 的缩写,在此网站不作为商标展示。
0
0
{"value":"This is the second post of a two-part series that covers how to store off-chain data using [Amazon Managed Blockchain](https://aws.amazon.com/managed-blockchain/) and [Amazon Simple Storage Service](https://aws.amazon.com/s3/) ([Amazon S3](https://aws.amazon.com/cn/s3/?trk=cndc-detail)). This post builds on the solution setup outlined in [Part 1](https://aws.amazon.com/blogs/database/part-1-store-off-chain-data-using-amazon-managed-blockchain-and-amazon-s3/).\n\nIn [Part 1](https://aws.amazon.com/blogs/database/part-1-store-off-chain-data-using-amazon-managed-blockchain-and-amazon-s3/), we presented a solution that implements off-chain storage for non-transactional data using [Amazon S3](https://aws.amazon.com/cn/s3/?trk=cndc-detail), and Managed Blockchain for Hyperledger Fabric for on-chain storage. One of the advantages offered by blockchain technology is that it’s tamper-proof. You can cryptographically verify the integrity of the data that has been stored on the ledger, known as on-chain data. However, there are also cases when off-chain data is needed to store any non-transactional data that is too large to store on-chain efficiently. We should also make sure that off-chain data has not been tampered with.\n\nIn this post, we show you how to fetch both on-chain and off-chain data in a single request, while verifying the integrity of the off-chain data.\n\n#### **Solution overview**\nThe following diagram illustrates the high-level architecture of the end-to-end solution.\n\n![image.png](https://dev-media.amazoncloud.cn/3be82359aa354f5eb94bedd7b10f00a8_image.png)\n\nIn [Part 1](https://aws.amazon.com/blogs/database/part-1-store-off-chain-data-using-amazon-managed-blockchain-and-amazon-s3/), we updated the “create new donor API” of the [non-profit blockchain workshop](https://github.com/aws-samples/non-profit-blockchain) to upload the donor image to [Amazon S3](https://aws.amazon.com/cn/s3/?trk=cndc-detail), and we stored the hash of it on the blockchain, along with the user name and email.\n\nIn this post, we update the “get donor API” to fetch the donor details from the blockchain ledger and the image from [Amazon S3](https://aws.amazon.com/cn/s3/?trk=cndc-detail) in a single API call. While fetching the image, we also verify the integrity of the file by comparing the hash value stored on the blockchain with the calculated hash value of the image stored in [Amazon S3](https://aws.amazon.com/cn/s3/?trk=cndc-detail). We use [AWS Step Functions](http://aws.amazon.com/step-functions) to orchestrate the steps to read data from the blockchain ledger, fetch images from [Amazon S3](https://aws.amazon.com/cn/s3/?trk=cndc-detail), and verify them.\n\nThe walkthrough includes the following steps:\n1. Create an [AWS Lambda](https://aws.amazon.com/lambda/) function to read the image from [Amazon S3](https://aws.amazon.com/cn/s3/?trk=cndc-detail).\n2. Create a workflow using Step Functions.\n3. Update the API to invoke the Step Functions workflow.\n4. Test the API in [Amazon API Gateway](https://aws.amazon.com/api-gateway/)\n\n#### **Prerequisites**\nBefore starting the walkthrough, you should complete the prerequisites and steps described in [Part 1](https://aws.amazon.com/blogs/database/part-1-store-off-chain-data-using-amazon-managed-blockchain-and-amazon-s3/).\n\n#### **Create a Lambda function to read the image from [Amazon S3](https://aws.amazon.com/cn/s3/?trk=cndc-detail)**\nWe first create a Lambda function to read the donor image from the S3 bucket and verify it. Then we configure an environment variable (```S3_BUCKET```) to pass the S3 bucket name to the function at runtime. The function reads the image from the S3 bucket, calculates the hash of it, and compares it with the hash value stored on the blockchain Ledger.\n\nIf both hash values are the same, it means the donor image hasn’t been tampered with. In this case, the Lambda function returns the image of the donor. If the hash values are different, the function returns the error message ```Donor Image is tampered```.\n\nThe following snippet of code provides sample Node.js code you can use to create the Lambda function:\n```\\nconst AWS = require('aws-sdk');\\nconst s3 = new AWS.S3();\\nexports.handler = async (event) => {\\n \\n let params = {\\n Bucket: process.env.S3_BUCKET, \\n Key: event.imageKey\\n };\\n \\n const response = {};\\n try {\\n const s3Response = await s3.getObject(params).promise();\\n if(event.imageHash == s3Response.ETag.replace(/\\\\\\"/g, \\"\\")){\\n response.donorUserName = event.donorUserName;\\n response.email = event.email;\\n response.image = s3Response.Body.toString('base64');\\n }\\n else{\\n response.error = \\"Donor Image is tampered.\\";\\n }\\n } catch (error) {\\n response.error = error.message;\\n }\\n return response;\\n};\\n```\nMake sure the function role is updated to grant the necessary permissions to read objects from the S3 bucket.\n\n#### **Create a workflow using Step Functions**\nBecause we stored donor data in two different systems, we have to make separate calls to these systems. Also, while fetching the donor image from [Amazon S3](https://aws.amazon.com/cn/s3/?trk=cndc-detail), we need to ensure that its integrity is preserved. We use Step Functions to orchestrate multiple API calls into a single workflow. In this step, we create a workflow using Step Functions to fetch data from the on-chain and off-chain storage.\n\nCreate a state machine in Step Functions by selecting the **Express** workflow type and using the following definition. Make sure you replace the required values in the JSON before using it.\n```\\n{\\n \\"Comment\\": \\"This is your state machine\\",\\n \\"StartAt\\": \\"InvokeQueryDonorChaincode\\",\\n \\"States\\": {\\n \\"InvokeQueryDonorChaincode\\": {\\n \\"Type\\": \\"Task\\",\\n \\"Resource\\": \\"arn:aws:states:::lambda:invoke\\",\\n \\"Parameters\\": {\\n \\"FunctionName\\": \\"<<ARN of the Lambda function to invoke Chaincode>>\\",\\n \\"Payload\\": {\\n \\"fabricUsername.\$\\": \\"\$.fabricUsername\\",\\n \\"functionType.\$\\": \\"\$.functionType\\",\\n \\"chaincodeFunction.\$\\": \\"\$.chaincodeFunction\\",\\n \\"chaincodeFunctionArgs\\": {\\n \\"donorUserName.\$\\": \\"\$.chaincodeFunctionArgs.donorUserName\\"\\n }\\n }\\n },\\n \\"Retry\\": [\\n {\\n \\"ErrorEquals\\": [\\n \\"Lambda.ServiceException\\",\\n \\"Lambda.AWSLambdaException\\",\\n \\"Lambda.SdkClientException\\"\\n ],\\n \\"IntervalSeconds\\": 2,\\n \\"MaxAttempts\\": 6,\\n \\"BackoffRate\\": 2\\n }\\n ],\\n \\"OutputPath\\": \\"\$.Payload\\",\\n \\"Next\\": \\"S3Read\\"\\n },\\n \\"S3Read\\": {\\n \\"Type\\": \\"Task\\",\\n \\"Resource\\": \\"arn:aws:states:::lambda:invoke\\",\\n \\"OutputPath\\": \\"\$.Payload\\",\\n \\"Parameters\\": {\\n \\"Payload.\$\\": \\"\$\\",\\n \\"FunctionName\\": \\"<<ARN of the Lambda function to fetch image from S3>>\\"\\n },\\n \\"Retry\\": [\\n {\\n \\"ErrorEquals\\": [\\n \\"Lambda.ServiceException\\",\\n \\"Lambda.AWSLambdaException\\",\\n \\"Lambda.SdkClientException\\"\\n ],\\n \\"IntervalSeconds\\": 2,\\n \\"MaxAttempts\\": 6,\\n \\"BackoffRate\\": 2\\n }\\n ],\\n \\"End\\": true\\n }\\n }\\n}\\n```\nAt this stage, the state machine should look like in the following screenshot:\n\n![image.png](https://dev-media.amazoncloud.cn/524718d270014b2494e81ced388a6b65_image.png)\n\nNext, update the role of the state machine to provide necessary permissions to invoke the Lambda functions.\n\nThe first function invokes the chaincode returning the donor user name, email, image key, and image hash. This information is passed to another function, which fetches the image from the S3 bucket using the key, calculates its hash, and compares the hash with the hash of the image received from the blockchain ledger.\n\n#### **Update the API to invoke the Step Functions workflow**\nIn [Part 1](https://aws.amazon.com/blogs/database/part-1-store-off-chain-data-using-amazon-managed-blockchain-and-amazon-s3/), you created an API in API Gateway. The resources in your API should look like the following screenshot.\n\n![image.png](https://dev-media.amazoncloud.cn/12dc22bcfe8a4611af474e1b24122e8f_image.png)\n\nYou also changed the integration for the POST method under the /{donors} resource to point to the Step Functions workflow. You now change the integration for the GET method under the /{donorUserName} resource to point to the Step Functions workflow created in the previous step. The updated integration settings should look like the following screenshot.\n\n![image.png](https://dev-media.amazoncloud.cn/4cdbb83960a24a148930a7a794378995_image.png)\n\nExpand the **Mapping Templates** section and update the template using the following JSON:\n```\\n{\\n \\"stateMachineArn\\":\\"<<ARN of the Step Functions workflow>>\\",\\n \\"input\\": \\"{\\n\\\\\\"fabricUsername\\\\\\": \\\\\\"lambdaUser1\\\\\\", \\n\\\\\\"functionType\\\\\\": \\\\\\"queryObject\\\\\\", \\n\\\\\\"chaincodeFunction\\\\\\": \\\\\\"queryDonor\\\\\\", \\n\\\\\\"chaincodeFunctionArgs\\\\\\": {\\n\\\\\\"donorUserName\\\\\\": \\\\\\"\$input.params('donorUserName')\\\\\\"\\n\\t}\\n }\\"\\n}\\n```\nThe GET method should look like the following screenshot after the update.\n\n![image.png](https://dev-media.amazoncloud.cn/ddcabfec0412454a8b28ab5a1076f7ac_image.png)\n\nChoose the **Integration Response** link, expand the **Mapping Templates** section, and update the template using following script:\n```\\n#if(\$input.path('\$.output'))\\n\$util.parseJson(\$input.json('\$.output'))\\n#else\\n\$util.parseJson(\$input.json('\$.cause'))\\n#end\\n```\n![image.png](https://dev-media.amazoncloud.cn/bcc4bc266b7b4c9a8fac95e3bf030f8e_image.png)\n\n#### **Test the API in API Gateway**\nTo test the API before it’s deployed, choose **Test** on the API Gateway console.\n\n![image.png](https://dev-media.amazoncloud.cn/3d58177b086647b6a4621056b2e82237_image.png)\n\nEnter the donor user name in the {```donorUserName```} field and choose **Test**.\n\n![image.png](https://dev-media.amazoncloud.cn/43a597c6baca4f4bbd5a6779dbfebf67_image.png)\n\nIf the donor image hasn’t been tampered with, the returned response should be the donor information along with a path to the image.\n\n![image.png](https://dev-media.amazoncloud.cn/17eefa257e004d489371c82845612ac9_image.png)\n\nIf the donor image has been tampered with, an error message is returned in the response.\n\n![image.png](https://dev-media.amazoncloud.cn/69cecfcdba294d71b4d2d66e05fd82cf_image.png)\n\n#### **Conclusion**\nThis series of posts demonstrated how to implement off-chain storage using Managed Blockchain and [Amazon S3](https://aws.amazon.com/cn/s3/?trk=cndc-detail).\n\nIn [Part 1](https://aws.amazon.com/blogs/database/part-1-store-off-chain-data-using-amazon-managed-blockchain-and-amazon-s3/), you implemented off-chain storage using [Amazon S3](https://aws.amazon.com/cn/s3/?trk=cndc-detail) and created a workflow using Step Functions to store off-chain data to [Amazon S3](https://aws.amazon.com/cn/s3/?trk=cndc-detail) and on-chain data on the blockchain in a single request.\n\nIn Part 2, you created a workflow using Step Functions to read data from both the on-chain and off-chain storage using a single request. While reading the data from the off-chain storage, you also validated its integrity.\n\nLet us know in the comments what you think about this series of posts.\n\n##### **About the Authors**\n\n![image.png](https://dev-media.amazoncloud.cn/c471c96085c14646ac640c4933271c6c_image.png)\n\n**Surya Jitendra Kumar Nallamalli** is a Solutions Architect at AWS. Surya is a SME in blockchain, data analytics, and cloud native development. In his free time, he enjoys spending time with his two daughters and watching web series.\n\n![image.png](https://dev-media.amazoncloud.cn/a9211dc0a01f432da49915e16fac77b9_image.png)\n\n**Bianca Buzea** was a Solutions Architect at AWS. Bianca enjoys working with customers and teaching them how to create innovative architectures using AWS services. She is passionate about blockchain technology and financial education. Outside of work, you can find her creating content for her personal blog and newsletter on these topics, or playing with sounds in Ableton.\n\n![image.png](https://dev-media.amazoncloud.cn/0d360926e8a94759b6b29f71487a4a82_image.png)\n\n**Meghan Gentry** is a Solutions Architect and blockchain specialist. She joined AWS 3 years ago as a member of the Military Apprentice Program after serving for 7 years in the United States Air Force. Meghan enjoys educating customers about all things cloud and helping them realize the art of the possible every day. She is excited to evangelize blockchain technology and distributed systems, especially as it pertains to decentralized finance (DeFi), improving state and federal government operations, and aiding in the progression of democracy all over the globe. When she isn’t working, Meghan is enjoying time with her husband, two young sons, two dogs, a cat, and several fish outside of Seattle.","render":"<p>This is the second post of a two-part series that covers how to store off-chain data using <a href=\\"https://aws.amazon.com/managed-blockchain/\\" target=\\"_blank\\">Amazon Managed Blockchain</a> and <a href=\\"https://aws.amazon.com/s3/\\" target=\\"_blank\\">Amazon Simple Storage Service</a> ([Amazon S3](https://aws.amazon.com/cn/s3/?trk=cndc-detail)). This post builds on the solution setup outlined in <a href=\\"https://aws.amazon.com/blogs/database/part-1-store-off-chain-data-using-amazon-managed-blockchain-and-amazon-s3/\\" target=\\"_blank\\">Part 1</a>.</p>\\n<p>In <a href=\\"https://aws.amazon.com/blogs/database/part-1-store-off-chain-data-using-amazon-managed-blockchain-and-amazon-s3/\\" target=\\"_blank\\">Part 1</a>, we presented a solution that implements off-chain storage for non-transactional data using [Amazon S3](https://aws.amazon.com/cn/s3/?trk=cndc-detail), and Managed Blockchain for Hyperledger Fabric for on-chain storage. One of the advantages offered by blockchain technology is that it’s tamper-proof. You can cryptographically verify the integrity of the data that has been stored on the ledger, known as on-chain data. However, there are also cases when off-chain data is needed to store any non-transactional data that is too large to store on-chain efficiently. We should also make sure that off-chain data has not been tampered with.</p>\\n<p>In this post, we show you how to fetch both on-chain and off-chain data in a single request, while verifying the integrity of the off-chain data.</p>\n<h4><a id=\\"Solution_overview_6\\"></a><strong>Solution overview</strong></h4>\\n<p>The following diagram illustrates the high-level architecture of the end-to-end solution.</p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/3be82359aa354f5eb94bedd7b10f00a8_image.png\\" alt=\\"image.png\\" /></p>\n<p>In <a href=\\"https://aws.amazon.com/blogs/database/part-1-store-off-chain-data-using-amazon-managed-blockchain-and-amazon-s3/\\" target=\\"_blank\\">Part 1</a>, we updated the “create new donor API” of the <a href=\\"https://github.com/aws-samples/non-profit-blockchain\\" target=\\"_blank\\">non-profit blockchain workshop</a> to upload the donor image to [Amazon S3](https://aws.amazon.com/cn/s3/?trk=cndc-detail), and we stored the hash of it on the blockchain, along with the user name and email.</p>\\n<p>In this post, we update the “get donor API” to fetch the donor details from the blockchain ledger and the image from Amazon S3 in a single API call. While fetching the image, we also verify the integrity of the file by comparing the hash value stored on the blockchain with the calculated hash value of the image stored in Amazon S3. We use <a href=\\"http://aws.amazon.com/step-functions\\" target=\\"_blank\\">AWS Step Functions</a> to orchestrate the steps to read data from the blockchain ledger, fetch images from [Amazon S3](https://aws.amazon.com/cn/s3/?trk=cndc-detail), and verify them.</p>\\n<p>The walkthrough includes the following steps:</p>\n<ol>\\n<li>Create an <a href=\\"https://aws.amazon.com/lambda/\\" target=\\"_blank\\">AWS Lambda</a> function to read the image from [Amazon S3](https://aws.amazon.com/cn/s3/?trk=cndc-detail).</li>\\n<li>Create a workflow using Step Functions.</li>\n<li>Update the API to invoke the Step Functions workflow.</li>\n<li>Test the API in <a href=\\"https://aws.amazon.com/api-gateway/\\" target=\\"_blank\\">Amazon API Gateway</a></li>\\n</ol>\n<h4><a id=\\"Prerequisites_21\\"></a><strong>Prerequisites</strong></h4>\\n<p>Before starting the walkthrough, you should complete the prerequisites and steps described in <a href=\\"https://aws.amazon.com/blogs/database/part-1-store-off-chain-data-using-amazon-managed-blockchain-and-amazon-s3/\\" target=\\"_blank\\">Part 1</a>.</p>\\n<h4><a id=\\"Create_a_Lambda_function_to_read_the_image_from_Amazon_S3_24\\"></a><strong>Create a Lambda function to read the image from Amazon S3</strong></h4>\\n<p>We first create a Lambda function to read the donor image from the S3 bucket and verify it. Then we configure an environment variable (<code>S3_BUCKET</code>) to pass the S3 bucket name to the function at runtime. The function reads the image from the S3 bucket, calculates the hash of it, and compares it with the hash value stored on the blockchain Ledger.</p>\\n<p>If both hash values are the same, it means the donor image hasn’t been tampered with. In this case, the Lambda function returns the image of the donor. If the hash values are different, the function returns the error message <code>Donor Image is tampered</code>.</p>\\n<p>The following snippet of code provides sample Node.js code you can use to create the Lambda function:</p>\n<pre><code class=\\"lang-\\">const AWS = require('aws-sdk');\\nconst s3 = new AWS.S3();\\nexports.handler = async (event) =&gt; {\\n \\n let params = {\\n Bucket: process.env.S3_BUCKET, \\n Key: event.imageKey\\n };\\n \\n const response = {};\\n try {\\n const s3Response = await s3.getObject(params).promise();\\n if(event.imageHash == s3Response.ETag.replace(/\\\\&quot;/g, &quot;&quot;)){\\n response.donorUserName = event.donorUserName;\\n response.email = event.email;\\n response.image = s3Response.Body.toString('base64');\\n }\\n else{\\n response.error = &quot;Donor Image is tampered.&quot;;\\n }\\n } catch (error) {\\n response.error = error.message;\\n }\\n return response;\\n};\\n</code></pre>\\n<p>Make sure the function role is updated to grant the necessary permissions to read objects from the S3 bucket.</p>\n<h4><a id=\\"Create_a_workflow_using_Step_Functions_59\\"></a><strong>Create a workflow using Step Functions</strong></h4>\\n<p>Because we stored donor data in two different systems, we have to make separate calls to these systems. Also, while fetching the donor image from Amazon S3, we need to ensure that its integrity is preserved. We use Step Functions to orchestrate multiple API calls into a single workflow. In this step, we create a workflow using Step Functions to fetch data from the on-chain and off-chain storage.</p>\n<p>Create a state machine in Step Functions by selecting the <strong>Express</strong> workflow type and using the following definition. Make sure you replace the required values in the JSON before using it.</p>\\n<pre><code class=\\"lang-\\">{\\n &quot;Comment&quot;: &quot;This is your state machine&quot;,\\n &quot;StartAt&quot;: &quot;InvokeQueryDonorChaincode&quot;,\\n &quot;States&quot;: {\\n &quot;InvokeQueryDonorChaincode&quot;: {\\n &quot;Type&quot;: &quot;Task&quot;,\\n &quot;Resource&quot;: &quot;arn:aws:states:::lambda:invoke&quot;,\\n &quot;Parameters&quot;: {\\n &quot;FunctionName&quot;: &quot;&lt;&lt;ARN of the Lambda function to invoke Chaincode&gt;&gt;&quot;,\\n &quot;Payload&quot;: {\\n &quot;fabricUsername.\$&quot;: &quot;\$.fabricUsername&quot;,\\n &quot;functionType.\$&quot;: &quot;\$.functionType&quot;,\\n &quot;chaincodeFunction.\$&quot;: &quot;\$.chaincodeFunction&quot;,\\n &quot;chaincodeFunctionArgs&quot;: {\\n &quot;donorUserName.\$&quot;: &quot;\$.chaincodeFunctionArgs.donorUserName&quot;\\n }\\n }\\n },\\n &quot;Retry&quot;: [\\n {\\n &quot;ErrorEquals&quot;: [\\n &quot;Lambda.ServiceException&quot;,\\n &quot;Lambda.AWSLambdaException&quot;,\\n &quot;Lambda.SdkClientException&quot;\\n ],\\n &quot;IntervalSeconds&quot;: 2,\\n &quot;MaxAttempts&quot;: 6,\\n &quot;BackoffRate&quot;: 2\\n }\\n ],\\n &quot;OutputPath&quot;: &quot;\$.Payload&quot;,\\n &quot;Next&quot;: &quot;S3Read&quot;\\n },\\n &quot;S3Read&quot;: {\\n &quot;Type&quot;: &quot;Task&quot;,\\n &quot;Resource&quot;: &quot;arn:aws:states:::lambda:invoke&quot;,\\n &quot;OutputPath&quot;: &quot;\$.Payload&quot;,\\n &quot;Parameters&quot;: {\\n &quot;Payload.\$&quot;: &quot;\$&quot;,\\n &quot;FunctionName&quot;: &quot;&lt;&lt;ARN of the Lambda function to fetch image from S3&gt;&gt;&quot;\\n },\\n &quot;Retry&quot;: [\\n {\\n &quot;ErrorEquals&quot;: [\\n &quot;Lambda.ServiceException&quot;,\\n &quot;Lambda.AWSLambdaException&quot;,\\n &quot;Lambda.SdkClientException&quot;\\n ],\\n &quot;IntervalSeconds&quot;: 2,\\n &quot;MaxAttempts&quot;: 6,\\n &quot;BackoffRate&quot;: 2\\n }\\n ],\\n &quot;End&quot;: true\\n }\\n }\\n}\\n</code></pre>\\n<p>At this stage, the state machine should look like in the following screenshot:</p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/524718d270014b2494e81ced388a6b65_image.png\\" alt=\\"image.png\\" /></p>\n<p>Next, update the role of the state machine to provide necessary permissions to invoke the Lambda functions.</p>\n<p>The first function invokes the chaincode returning the donor user name, email, image key, and image hash. This information is passed to another function, which fetches the image from the S3 bucket using the key, calculates its hash, and compares the hash with the hash of the image received from the blockchain ledger.</p>\n<h4><a id=\\"Update_the_API_to_invoke_the_Step_Functions_workflow_130\\"></a><strong>Update the API to invoke the Step Functions workflow</strong></h4>\\n<p>In <a href=\\"https://aws.amazon.com/blogs/database/part-1-store-off-chain-data-using-amazon-managed-blockchain-and-amazon-s3/\\" target=\\"_blank\\">Part 1</a>, you created an API in API Gateway. The resources in your API should look like the following screenshot.</p>\\n<p><img src=\\"https://dev-media.amazoncloud.cn/12dc22bcfe8a4611af474e1b24122e8f_image.png\\" alt=\\"image.png\\" /></p>\n<p>You also changed the integration for the POST method under the /{donors} resource to point to the Step Functions workflow. You now change the integration for the GET method under the /{donorUserName} resource to point to the Step Functions workflow created in the previous step. The updated integration settings should look like the following screenshot.</p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/4cdbb83960a24a148930a7a794378995_image.png\\" alt=\\"image.png\\" /></p>\n<p>Expand the <strong>Mapping Templates</strong> section and update the template using the following JSON:</p>\\n<pre><code class=\\"lang-\\">{\\n &quot;stateMachineArn&quot;:&quot;&lt;&lt;ARN of the Step Functions workflow&gt;&gt;&quot;,\\n &quot;input&quot;: &quot;{\\n\\\\&quot;fabricUsername\\\\&quot;: \\\\&quot;lambdaUser1\\\\&quot;, \\n\\\\&quot;functionType\\\\&quot;: \\\\&quot;queryObject\\\\&quot;, \\n\\\\&quot;chaincodeFunction\\\\&quot;: \\\\&quot;queryDonor\\\\&quot;, \\n\\\\&quot;chaincodeFunctionArgs\\\\&quot;: {\\n\\\\&quot;donorUserName\\\\&quot;: \\\\&quot;\$input.params('donorUserName')\\\\&quot;\\n\\t}\\n }&quot;\\n}\\n</code></pre>\\n<p>The GET method should look like the following screenshot after the update.</p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/ddcabfec0412454a8b28ab5a1076f7ac_image.png\\" alt=\\"image.png\\" /></p>\n<p>Choose the <strong>Integration Response</strong> link, expand the <strong>Mapping Templates</strong> section, and update the template using following script:</p>\\n<pre><code class=\\"lang-\\">#if(\$input.path('\$.output'))\\n\$util.parseJson(\$input.json('\$.output'))\\n#else\\n\$util.parseJson(\$input.json('\$.cause'))\\n#end\\n</code></pre>\\n<p><img src=\\"https://dev-media.amazoncloud.cn/bcc4bc266b7b4c9a8fac95e3bf030f8e_image.png\\" alt=\\"image.png\\" /></p>\n<h4><a id=\\"Test_the_API_in_API_Gateway_167\\"></a><strong>Test the API in API Gateway</strong></h4>\\n<p>To test the API before it’s deployed, choose <strong>Test</strong> on the API Gateway console.</p>\\n<p><img src=\\"https://dev-media.amazoncloud.cn/3d58177b086647b6a4621056b2e82237_image.png\\" alt=\\"image.png\\" /></p>\n<p>Enter the donor user name in the {<code>donorUserName</code>} field and choose <strong>Test</strong>.</p>\\n<p><img src=\\"https://dev-media.amazoncloud.cn/43a597c6baca4f4bbd5a6779dbfebf67_image.png\\" alt=\\"image.png\\" /></p>\n<p>If the donor image hasn’t been tampered with, the returned response should be the donor information along with a path to the image.</p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/17eefa257e004d489371c82845612ac9_image.png\\" alt=\\"image.png\\" /></p>\n<p>If the donor image has been tampered with, an error message is returned in the response.</p>\n<p><img src=\\"https://dev-media.amazoncloud.cn/69cecfcdba294d71b4d2d66e05fd82cf_image.png\\" alt=\\"image.png\\" /></p>\n<h4><a id=\\"Conclusion_184\\"></a><strong>Conclusion</strong></h4>\\n<p>This series of posts demonstrated how to implement off-chain storage using Managed Blockchain and Amazon S3.</p>\n<p>In <a href=\\"https://aws.amazon.com/blogs/database/part-1-store-off-chain-data-using-amazon-managed-blockchain-and-amazon-s3/\\" target=\\"_blank\\">Part 1</a>, you implemented off-chain storage using [Amazon S3](https://aws.amazon.com/cn/s3/?trk=cndc-detail) and created a workflow using Step Functions to store off-chain data to [Amazon S3](https://aws.amazon.com/cn/s3/?trk=cndc-detail) and on-chain data on the blockchain in a single request.</p>\\n<p>In Part 2, you created a workflow using Step Functions to read data from both the on-chain and off-chain storage using a single request. While reading the data from the off-chain storage, you also validated its integrity.</p>\n<p>Let us know in the comments what you think about this series of posts.</p>\n<h5><a id=\\"About_the_Authors_193\\"></a><strong>About the Authors</strong></h5>\\n<p><img src=\\"https://dev-media.amazoncloud.cn/c471c96085c14646ac640c4933271c6c_image.png\\" alt=\\"image.png\\" /></p>\n<p><strong>Surya Jitendra Kumar Nallamalli</strong> is a Solutions Architect at AWS. Surya is a SME in blockchain, data analytics, and cloud native development. In his free time, he enjoys spending time with his two daughters and watching web series.</p>\\n<p><img src=\\"https://dev-media.amazoncloud.cn/a9211dc0a01f432da49915e16fac77b9_image.png\\" alt=\\"image.png\\" /></p>\n<p><strong>Bianca Buzea</strong> was a Solutions Architect at AWS. Bianca enjoys working with customers and teaching them how to create innovative architectures using AWS services. She is passionate about blockchain technology and financial education. Outside of work, you can find her creating content for her personal blog and newsletter on these topics, or playing with sounds in Ableton.</p>\\n<p><img src=\\"https://dev-media.amazoncloud.cn/0d360926e8a94759b6b29f71487a4a82_image.png\\" alt=\\"image.png\\" /></p>\n<p><strong>Meghan Gentry</strong> is a Solutions Architect and blockchain specialist. She joined AWS 3 years ago as a member of the Military Apprentice Program after serving for 7 years in the United States Air Force. Meghan enjoys educating customers about all things cloud and helping them realize the art of the possible every day. She is excited to evangelize blockchain technology and distributed systems, especially as it pertains to decentralized finance (DeFi), improving state and federal government operations, and aiding in the progression of democracy all over the globe. When she isn’t working, Meghan is enjoying time with her husband, two young sons, two dogs, a cat, and several fish outside of Seattle.</p>\n"}
目录
亚马逊云科技解决方案 基于行业客户应用场景及技术领域的解决方案
联系亚马逊云科技专家
亚马逊云科技解决方案
基于行业客户应用场景及技术领域的解决方案
联系专家
0
目录
关闭