Hướng dẫn dùng aws samples python
This version of the AWS Code Sample Catalog has been replaced by the AWS Code Library, which contains new and updated code examples. Show The examples listed on this page are code samples written in Python that demonstrate how to interact with AWS Lambda. For more information, see the AWS SDK for Python (Boto3) Getting Started and the AWS Lambda Developer Guide.
In this tutorial, you use the console to create a Lambda function and configure a trigger for Amazon Simple Storage Service (Amazon S3). The trigger invokes your function every time that you add an object to your Amazon S3 bucket. We recommend that you complete this console-based tutorial before you try the tutorial to create thumbnail images. PrerequisitesTo use Lambda and other AWS services, you need an AWS account. If you do not have an account, visit aws.amazon.com and choose Create an AWS Account. For instructions, see How do I create and activate a new AWS account? This tutorial assumes that you have some knowledge of basic Lambda operations and the Lambda console. If you haven't already, follow the instructions in Create a Lambda function with the console to create your first Lambda function. Create a bucket and upload a sample objectCreate an Amazon S3 bucket and upload a test file to your new bucket. Your Lambda function retrieves information about this file when you test the function from the console. To create an Amazon S3 bucket using the console
After creating the bucket, Amazon S3 opens the Buckets page, which displays a list of all buckets in your account in the current Region. To upload a test object using the Amazon S3 console
Create the Lambda functionUse a function blueprint to create the Lambda function. A blueprint provides a sample function that demonstrates how to use Lambda with other AWS services. Also, a blueprint includes sample code and function configuration presets for a certain runtime. For this tutorial, you can choose the blueprint for the Node.js or Python runtime. To create a Lambda function from a blueprint in the console
Review the function codeThe Lambda function retrieves the source S3 bucket name and the key name of the uploaded object from the event parameter that it receives. The function uses the Amazon S3 While viewing your function in the Lambda console , you can review the function code on the Code tab, under Code source. The code looks like the following: Test in the consoleInvoke the Lambda function manually using sample Amazon S3 event data. To test the Lambda function using the console
Test with the S3 triggerInvoke your function when you upload a file to the Amazon S3 source bucket. To test the Lambda function using the S3 trigger
Clean up your resourcesYou can now delete the resources that you created for this tutorial, unless you want to retain them. By deleting AWS resources that you're no longer using, you prevent unnecessary charges to your AWS account. To delete the Lambda function
To delete the IAM policy
To delete the execution role
To delete the S3 bucket
Next stepsTry the more advanced tutorial. In this tutorial, the S3 trigger invokes a function to create a thumbnail image for each image file that is uploaded to your S3 bucket. This tutorial requires a moderate level of AWS and Lambda domain knowledge. You use the AWS Command Line Interface (AWS CLI) to create resources, and you create a .zip file archive deployment package for your function and its dependencies. |