Skip to content

LambdaSharp/Image-Tweeter-Challenge

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Build a Serverless .NET Core Image Tweeter

In this challenge we're going to learn how to trigger an AWS Lambda function when a file is uploaded to Amazon S3. That AWS Lambda function will take the uploaded file and tweet the image to a Twitter account.

Prerequisites

  1. AWS Tools
    1. Sign-up for an AWS account
    2. Install AWS CLI
  2. .NET Core
    1. Install .NET Core 1.0 (NOTE: You MUST install 1.0. Do NOT install 1.1 or later!)
    2. Install Visual Studio Code
    3. Install C# Extension for VS Code
  3. AWS C# Lambda Tools
    1. Install Nodejs
    2. Install Yeoman
    3. Install AWS C# Lambda generator: npm install -g yo generator-aws-lambda-dotnet

Level 1: Trigger an AWS Lambda function from Amazon S3

For level 1, you will need to create an Amazon S3 bucket, create an AWS IAM role and policy, deploy an AWS Lambda function and use Amazon CloudWatch to debug and monitor. Use us-west-2 aka US West Oregon region. Below are some hints to help you get started.

AWS IAM role:

Deploy the AWS Lambda starter function:

  • Run the following in terminal as you need, from the ImageTweeter directory.

    • To refresh dependencies: dotnet restore
    • To build the lambda function: dotnet build
    • To publish the lambda function: dotnet publish
    • To deploy the lambda function: dotnet lambda deploy-function -fn lamda-sharp-image-tweeter

Note: On first deployment it will ask you for a role. Choose the role you created earlier. If you do not see it in the list, check your Trust Relationship for the role that it allows lambda.amazonaws.com.

Amazon S3 bucket:

  • The bucket name must be unique.
  • Add an event on the bucket that triggers the AWS Lambda function.
  • For this project you can use images from aws/images or use your own.

ACCEPTANCE TEST: The lambda function is triggered by uploading an image to Amazon S3. Look in Amazon CloudWatch for log message Hello from The AutoMaTweeter!.

Level 2: Log the bucket and key from the Amazon S3 event

For level 2, modify the LambdaHandler.cs file in src/ImageTweeter to read the Amazon S3 event notification. Get the bucket and key name from the event and output to Amazon CloudWatch.

You can use the imports from the LambdaHandler.cs file and the AWS SDK for .NET documentation as a reference.

ACCEPTANCE TEST: The Amazon S3 bucket and key name appear in the Amazon CloudWatch logs.

Level 3: Post the image uploaded to Twitter

For level 3, modify the code to post the uploaded image to Twitter with a message. TweetInvi is the library I used and included it as a depedency in this project. You'll also need to modify the Amazon S3 bucket and AWS IAM policy.

Amazon S3 bucket:

AWS IAM role:

Twitter API Keys:

  • You will also need 4 Twitter API keys: consumer key, consumer secret, access token, and access token secret, which I will provide for tonight's project.
  • You can view the tweets at: https://twitter.com/the_automatweet
  • If you'd like keys for your account, you can get them on the Twitter App site.

Note: I had some conflicting namespace and functions at times. If you have this issue, my workaround was to create my own namespace using AmazonRekognitionModel = Amazon.Rekognition.Model;

ACCEPTANCE TEST: After the image is uploaded to Amazon S3 it will post to Twitter.

Boss Level: Analyze the image with Amazon Rekognition

For the boss level, use Amazon Rekognition to tweet keyword descriptions of the image uploaded to Amazon S3.

ACCEPTANCE TEST: The tweet includes an the image uploaded and a list of words that describe the image.

Have fun!! 😄

Releases

No releases published

Packages

No packages published

Languages