Skip to content

Snake Game is simple mobile game for Android devices where the snake eats the apples and gets longer and longer as it eats them. It serves as a sample app to show how to use different AWS Mobile Services together.

License

Notifications You must be signed in to change notification settings

jinman/snake-game-aws

Repository files navigation

Running the Snake Game - AWS Mobile Services Sample App

Snake Game is simple mobile game for Android devices where the snake eats the apples and gets longer and longer as it eats them. It serves as a sample app to show how to use different AWS Mobile Services together.

It uses the AWS Android SDK and number of AWS Mobile Services:

  • Amazon Cognito identity (Amazon, Facebook and Google+) to authenticate users via social logins.
  • Amazon Cognito identity for unauthenticated identities "Just Play"
  • Amazon Cognito Sync to sync game preferences (Level of the game)
  • Amazon S3 to upload screenshot to S3 (Game over screen with high scores)
  • Amazon S3 to download game assets dynamically and updates the UI to “Christmas theme” or FIFA Theme
  • Amazon DynamoDB to GET highScore
  • Amazon DynamoDB to PUT last score
  • Amazon Mobile Analytics to start and stop session (also custom events)
  • Amazon Kinesis to capture Logcat data (crash reports and clickstreams)
  • (New!) AWS Lambda to synchronously invoke cloud functions (shows a toast on app start "Hello From Lambda")
  1. Import the project Snake Game - AWS into Eclipse

    • Go to File -> Import. Import Wizard will open.
    • Select General -> Existing Projects into Workspace. Click Next.
    • In Select root directory, browse to samples directory. List of all samples projects will appear.
    • Select the 'Snake Game - AWS' project to import
    • Click Finish.
  2. Copy the AWS SDK for Android jar into the libs directory for the project. Include the following jars under libs/debug directory (for release purposes, you can include the release jars under libs/release directory)

    • aws-android-sdk-X.X.X-core.debug.jar
    • extras/aws-android-sdk-X.X.X-cognito.debug.jar
    • For example:
    • aws-android-sdk-2.2.0-kinesis.jar
    • aws-android-sdk-2.2.0-cognito.jar
    • aws-android-sdk-2.2.0-mobileanalytics.jar
    • aws-android-sdk-2.2.0-core.jar
    • aws-android-sdk-2.2.0-s3.jar
    • aws-android-sdk-2.2.0-ddb-mapper.jar
    • aws-android-sdk-2.2.0-sns.jar
    • aws-android-sdk-2.2.0-ddb.jar
    • aws-android-sdk-2.2.0-lambda.jar
  3. Update the path to the FacebookSDK or google-play-services_lib in project.properties. By default it points to the one included in the repo so if you just cloned the project and didn't move any of the directories this should not be necessary. (While Facebook Login is not required to run the app, the SDK is still required to build).

  4. Using AWS Management Console, create following cloud resources

    • An S3 bucket. Add a file with the name "Archive.zip" for the S3 download demo to the S3 bucket

    • A DynamoDB table. Hash Key: userid (String), Range key: recordid (String)

    • A Kinesis stream

    • A Cognito identity pool with a Login with Amazon, a Facebook identity and Google+ tokens

    • Edit IAM Policies for UnAuth Role, Auth Role so it can access, Kinesis, DynamoDB, Mobile Analytics, Lambda and so on

    • A Lambda Function "cloudFunction" with default roles and config Add the following to the "HelloWorld" app

        context.done(null, event + 'Lambda'); //will send "Hello From Lambda"
  5. Update your App configuration:

    • Make sure you have an identity pool created and configured at https://console.aws.amazon.com/cognito/ and you downloaded the starter code at the last step of the wizard.

    • Open CognitoSyncClientManager.java

    • Update "AWS_ACCOUNT_ID", "IDENTITY_POOL_ID", "UNAUTH_ROLE_ARN", and "AUTH_ROLE_ARN" with the values from the starter code.

      public static final String AWS_ACCOUNT_ID = "<your account number from AWS Management Console/MyAccount>";
      public static final String COGNITO_POOL_ID = "<your cognito identity pool id from AWS Management Console/Cognito>";
      public static final String COGNITO_ROLE_AUTH = "<your IAM role for auth from AWS Management Console/Cognito>";
      public static final String COGNTIO_ROLE_UNAUTH = "<your IAM role for unauth from AWS Management Console/Cognito>";
      public static final String S3_BUCKET_NAME = "<your bucketname from AWS Management Console/S3>";
      public static final String DDB_TABLE_NAME = "<your table name from AWS Management Console/DynamoDB";
      public static final String KINESIS_STREAM_NAME = "<your stream name from AWS Management Console/S3";
      public static final String KINESIS_DIRECTORY_NAME = "snakegamekinesisdirectory";
      public static final String COGNITO_SYNC_DATASET_NAME = "snakegamestate";   
      public static final String MOBILE_ANALYTICS_APP_ID = "SnakeGameAWS"; 
    • At this point you can run the sample if you have the support of unauthenticated identity configured in the identity pool.

      • Go to Project -> Clean.
      • Go to Project -> Build All.
      • Go to Run -> Run.
    • To support Facebook Login, Login with Amazon, Google+, continue with step below.

  6. To add support for Facebook Login (Optional)

    • Follow the instructions at https://developers.facebook.com/docs/android/getting-started/ to create a Facebook app
      • For "Package Name", enter com.amazonaws.cognito.sync.demo
      • For "Class Name", enter com.amazonaws.cognito.sync.demo.MainActivity
    • Make sure your identity pool is configured to support Facebook login by entering the Facebook app ID at https://console.aws.amazon.com/cognito/ from the previous step.
    • Import the Facebook SDK into Eclipse following https://developers.facebook.com/docs/android/getting-started/
    • Link to the Facebook SDK project and configure the Facebook app ID
      • Open the strings.xml file located in res/values
      • Update "facebook_app_id" with the app ID of the app you created
      • Open project properties and under Android remove the placeholder Facebook library "path/to/facebook/sdk" and add "FacebookSDK"
    • At this point you can run the sample with Facebook Login.
  7. To add support for Login with Amazon. (Optional)

    • Follow the instructions at https://login.amazon.com/android to register a new application
      • For "Label", enter Cognito sync demo
      • For "Package Name", enter com.amazonaws.cognito.sync.demo
    • Make sure your identity pool is configured to support Login with Amazon by entering the Client ID at https://console.aws.amazon.com/cognito/ from the previous step.
    • Copy and paste the API key amzn_api_key in strings.xml
    • If this isn't configured properly, the "Login with Amazon" button will be disabled in the sample app.
  8. To add support for Google+ Signin. (Optional)

    • Follow the instructions at https://code.google.com/apis/console to create a new Project
    • Create a new Client ID under APIs & Auth > Credentials
      • Select "Service Account"
    • Make sure your identity pool is configured to support Login with Amazon by entering the Client ID at https://console.aws.amazon.com/cognito/ from the previous step.
    • Copy and paste the client id to google_client_id key in strings.xml
    • If this isn't configured properly, the "Login with Amazon" button will be disabled in the sample app.

About

Snake Game is simple mobile game for Android devices where the snake eats the apples and gets longer and longer as it eats them. It serves as a sample app to show how to use different AWS Mobile Services together.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages