aws-samples / api-gateway-secure-pet-store

Amazon API Gateway sample using Amazon Cognito credentials through AWS Lambda
Apache License 2.0
308 stars 113 forks source link

Setup the Secure Pet Store

Introduction

The Secure Pet Store sample is an application built in Java for AWS Lambda. It uses Amazon API Gateway to expose the Lambda function as HTTP endpoints and uses Identity and Access Management (IAM) and Amazon Cognito to retrieve temporary credentials for a user and authorize access to its APIs with.

The Secure Pet Store

Build and Deploy the Application to AWS Lambda

The application needs to be modified to reflect the resource names created above. After adapting the configuration you package the application and deploy it as an AWS Lambda function with the necessary execution role.

Setting up the iOS sample

Introduction

The iOS sample application is located under the /src/main/resources/ios_sample folder. It uses CocoaPods to retrieve its dependencies and includes an iOS client SDK generated with API Gateway.

Step by Step setup

The AWSCredentialsProvider

In order to provide credentials to our SDK, and make calls to the Secure Pet Store backend, we have created a custom implementation of the AWSCredentialsProvider object. The AWSCredentialsProvider interface declares a single method, (AWSTask *)refresh. This method is called by the generated SDK whenever it needs credentials and is in charge of fetching a new set of temporary AWS credentials from your backend and storing them in its _accessKey, _secretKey, and session_key properties.

Our custom implementation is located under PetTest/APIGSessionCredentialsProvider. The refresh method uses the generated client to call the login method with a cached username and password. The login method from our backend verifies the credentials and responds with a set of temporary AWS credentials.