diff --git a/docs/source/conf.py b/docs/source/conf.py index efb2a49..6208bbc 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -89,7 +89,9 @@ # further. For a list of options available for each theme, see the # documentation. # -# html_theme_options = {} +html_theme_options = { + 'show_relbar_bottom': True +} # Add any paths that contain custom static files (such as style sheets) here, # relative to this directory. They are copied after the builtin static files, diff --git a/docs/source/env-setup.rst b/docs/source/env-setup.rst index 7605e47..6648cdb 100644 --- a/docs/source/env-setup.rst +++ b/docs/source/env-setup.rst @@ -9,7 +9,12 @@ development environment must have: * AWS credentials * git -If you have all of the above requirements, you can skip this step entirely. +If you have all of the above requirements, you can skip these steps entirely. + +.. contents:: + :local: + :depth: 1 + Setting up Python ----------------- @@ -174,11 +179,13 @@ To actually set up AWS credentials on your development environment, use the AWS CLI. To check if you have the AWS CLI installed, run:: $ aws --version - aws-cli/1.11.126 Python/3.6.5 Darwin/15.6.0 botocore/1.7.30 + aws-cli/1.15.60 Python/3.6.5 Darwin/15.6.0 botocore/1.10.59 -If it prints out a version such as ``aws-cli/1.11.126 Python/3.6.5 Darwin/15.6.0 botocore/1.7.30``, that means you have the AWS CLI installed on your -developement environment. +If it prints out a version, that means you have the AWS CLI installed on your +development environment. To get credentials set, it should not matter what +version of the AWS CLI you are using. The tutorial you choose to follow will +inform you if you need a specific version of the AWS CLI. If you do not have the AWS CLI installed, you can install it by following the instructions in the `user guide `__. Assuming ``pip`` is installed on your development diff --git a/docs/source/media-query/00-intro-chalice.rst b/docs/source/media-query/00-intro-chalice.rst index 288508c..b5cb712 100644 --- a/docs/source/media-query/00-intro-chalice.rst +++ b/docs/source/media-query/00-intro-chalice.rst @@ -100,7 +100,7 @@ Instructions $ cd workshop-intro -2. Open the ``app.py`` file and delete all lines of code underneath +2. Open the ``app.py`` file and delete **all** lines of code underneath the line: ``app = Chalice(app_name='workshop-intro')``. Your ``app.py`` file should only consist of the following lines:: diff --git a/docs/source/media-query/02-chalice-with-rekognition.rst b/docs/source/media-query/02-chalice-with-rekognition.rst index 0e8bb6e..a0f7971 100644 --- a/docs/source/media-query/02-chalice-with-rekognition.rst +++ b/docs/source/media-query/02-chalice-with-rekognition.rst @@ -21,28 +21,6 @@ application: :depth: 1 -Install Chalice ---------------- - -This step will ensure that ``chalice`` is installed in your virtualenv. - -Instructions -~~~~~~~~~~~~ - -1. Install ``chalice`` inside of your virtualenv:: - - $ pip install chalice - - -Verification -~~~~~~~~~~~~ - -To make sure ``chalice`` was installed correctly, run:: - - $ chalice --version - - - Create a new Chalice project ---------------------------- Create the new Chalice project for the Media Query application. @@ -82,27 +60,22 @@ Instructions $ git clone https://github.com/aws-samples/chalice-workshop.git -2. Copy over the ``chalicelib`` directory. This will contain utility modules - for the application:: +2. Copy over the starting point code for section ``02-chalice-with-rekognition`` + into your ``media-query`` directory:: - $ cp -r chalice-workshop/code/media-query/02-chalice-with-rekognition/chalicelib media-query/ + $ cp -r chalice-workshop/code/media-query/02-chalice-with-rekognition/ media-query/ + .. note:: -3. Copy over the ``.chalice/config.json`` and the ``.chalice/policy-dev.json``. - The ``.chalice/config.json`` manages configuration of the Chalice - application, and ``.chalice/policy-dev.json`` manages AWS permissions for - the Chalice application:: + If you are ever stuck and want to skip to the beginning of a different + part of this tutorial, you can do this by running the same command + as above, but instead use the ``code`` directory name of the part you + want to skip to. For example, if you wanted to skip to the beginning of + Part 5 of this tutorial, you can run the following command with + ``media-query`` as the current working directory and be ready to start + Part 5:: - $ cp chalice-workshop/code/media-query/02-chalice-with-rekognition/.chalice/config.json media-query/.chalice - $ cp chalice-workshop/code/media-query/02-chalice-with-rekognition/.chalice/policy-dev.json media-query/.chalice - - -4. Copy over the ``resources.json`` file and ``recordresources.py``. These two - files will be used to deploy and integrate AWS resources into the - Chalice application:: - - $ cp chalice-workshop/code/media-query/02-chalice-with-rekognition/resources.json media-query/ - $ cp chalice-workshop/code/media-query/02-chalice-with-rekognition/recordresources.py media-query/ + media-query$ cp -r ../chalice-workshop/code/media-query/05-s3-delete-event/ ./ Verification @@ -124,6 +97,35 @@ Verification ├── requirements.txt └── resources.json + For the files that got added, they will be used later in the tutorial but + for a brief overview of the new files: + + * ``chalicelib``: A directory for managing Python modules outside of the + ``app.py``. It is common to put the lower-level logic in the + ``chalicelib`` directory and keep the higher level logic in the + ``app.py`` file so it stays readable and small. You can read more + about ``chalicelib`` in the Chalice + `documentation `__. + + * ``chalicelib/rekognition.py``: A utility module to further simplify + ``boto3`` client calls to Amazon Rekognition. + + * ``.chalice/config.json``: Manages configuration of the Chalice + application. You can read more about the configuration file in + the Chalice `documentation `__. + + * ``.chalice/policy-dev.json``: The IAM policy to apply to your Lambda + function. This essentially manages the AWS permissions of your + application + + * ``resources.json``: A CloudFormation template with additional resources + to deploy outside of the Chalice application. + + * ``recordresources.py``: Records resource values from the additional + resources deployed to your CloudFormation stack and saves them + as environment variables in your Chalice application . + + Write a Lambda function for detecting labels -------------------------------------------- @@ -155,7 +157,7 @@ Instructions app = Chalice(app_name='media-query') -4. Import ``boto3`` and the ``chalicelib.rekognition`` module in your +3. Import ``boto3`` and the ``chalicelib.rekognition`` module in your ``app.py`` file: .. literalinclude:: ../../../code/media-query/03-add-db/app.py @@ -253,23 +255,12 @@ Verification $ aws s3 cp ../chalice-workshop/code/media-query/final/assets/sample.jpg s3://$MEDIA_BUCKET_NAME -2. Print out the value of ``MEDIA_BUCKET_NAME``:: - - $ echo $MEDIA_BUCKET_NAME - media-query-mediabucket-fb8oddjbslv1 - - -3. Create a ``sample-event.json`` file to use with ``chalice invoke``. Using - the value from ``MEDIA_BUCKET_NAME`` as the value of the ``Bucket`` key in - the sample event, the contents of the file should be:: +2. Create a ``sample-event.json`` file to use with ``chalice invoke``:: - { - "Bucket": "media-query-mediabucket-fb8oddjbslv1", - "Key": "sample.jpg" - } + $ echo "{\"Bucket\": \"$MEDIA_BUCKET_NAME\", \"Key\": \"sample.jpg\"}" > sample-event.json -2. Run ``chalice invoke`` on the ``detect_labels_on_image`` Lambda function:: +3. Run ``chalice invoke`` on the ``detect_labels_on_image`` Lambda function:: $ chalice invoke --name detect_labels_on_image < sample-event.json diff --git a/docs/source/media-query/03-add-db.rst b/docs/source/media-query/03-add-db.rst index c9c749e..8d5e2e1 100644 --- a/docs/source/media-query/03-add-db.rst +++ b/docs/source/media-query/03-add-db.rst @@ -22,12 +22,14 @@ Copy over files needed for integrating the DynamoDB table into the application Instructions ~~~~~~~~~~~~ -1. Copy the ``db.py`` module into the ``chalicelib`` package:: +1. Using ``media-query`` as the current working directory, copy the ``db.py`` + module into the ``chalicelib`` package:: $ cp ../chalice-workshop/code/media-query/03-add-db/chalicelib/db.py chalicelib/ -2. Copy over an updated version of the ``resources.json`` file:: +2. Using ``media-query`` as the current working directory, copy over an updated + version of the ``resources.json`` file:: $ cp ../chalice-workshop/code/media-query/03-add-db/resources.json . diff --git a/docs/source/media-query/07-videos.rst b/docs/source/media-query/07-videos.rst index f773f37..01babc8 100644 --- a/docs/source/media-query/07-videos.rst +++ b/docs/source/media-query/07-videos.rst @@ -178,8 +178,8 @@ Instructions 3. Update the ``add_video_file()`` function, to process the ``event`` argument of type `SNSEvent `__ - by retrieving the job ID from the message, retrieving the processed labels - from Rekognition, and adding the video to the database: + by retrieving the job ID from the message, retrieve the processed labels + from Rekognition, and add the video to the database: .. literalinclude:: ../../../code/media-query/final/app.py :lines: 58-65 @@ -263,7 +263,7 @@ Verification "type": "video" } -Automate video workflow on S3 uploads and downloads +Automate video workflow on S3 uploads and deletions --------------------------------------------------- Now let's update the application so we do not have to manually invoke the @@ -392,10 +392,63 @@ Verification Final Code ---------- Congratulations! You have now completed this tutorial. Below is the final code -that you should have wrote in the ``app.py`` of your application: +that you should have wrote in the ``app.py`` of your Chalice application: .. literalinclude:: ../../../code/media-query/final/app.py :linenos: For the complete final application, see the `GitHub repository `__ + + +Cleaning up the Chalice application +----------------------------------- + +Now that you have completed this tutorial, you may want to clean up the AWS +resources running this application. This step provides instructions on how +you can clean up your deployed resources once you are done using this application. + +Instructions +~~~~~~~~~~~~ + + +1. Delete the chalice application:: + + $ chalice delete + Deleting Rest API: kyfn3gqcf0 + Deleting function: arn:aws:lambda:us-west-2:123456789123:function:media-query-dev + Deleting IAM role: media-query-dev-api_handler + Deleting function: arn:aws:lambda:us-west-2:123456789123:function:media-query-dev-add_video_file + Deleting IAM role: media-query-dev-add_video_file + Deleting function: arn:aws:lambda:us-west-2:123456789123:function:media-query-dev-handle_object_removed + Deleting IAM role: media-query-dev-handle_object_removed + Deleting function: arn:aws:lambda:us-west-2:123456789123:function:media-query-dev-handle_object_created + Deleting IAM role: media-query-dev-handle_object_created + +2. Delete all objects in your S3 bucket:: + + $ aws s3 rm s3://$MEDIA_BUCKET_NAME --recursive + delete: s3://media-query-mediabucket-4b1h8anboxpa/sample.jpg + delete: s3://media-query-mediabucket-4b1h8anboxpa/sample.mp4 + +3. Delete the CloudFormation stack containing the additional AWS resources:: + + $ aws cloudformation delete-stack --stack-name media-query + +Validation +~~~~~~~~~~ + +1. Ensure that the API for the application no longer exists:: + + $ chalice url + Error: Could not find a record of a Rest API in chalice stage: 'dev' + + +2. Check the existence of a couple of resources from the CloudFormation stack + to make sure the resources no longer exist:: + + $ aws s3 ls s3://$MEDIA_BUCKET_NAME + An error occurred (NoSuchBucket) when calling the ListObjects operation: The specified bucket does not exist + + $ aws dynamodb describe-table --table-name $MEDIA_TABLE_NAME + An error occurred (ResourceNotFoundException) when calling the DescribeTable operation: Requested resource not found: Table: media-query-MediaTable-YIM7BMEIOF8Y not found