All Projects → aws-samples → Aws Cognito Apigw Angular Auth

aws-samples / Aws Cognito Apigw Angular Auth

Licence: other
A simple/sample AngularV4-based web app that demonstrates different API authentication options using Amazon Cognito and API Gateway with an AWS Lambda and Amazon DynamoDB backend that stores user details in a complete end to end Serverless fashion.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Aws Cognito Apigw Angular Auth

Hands-On-Serverless-Applications-with-Go
Hands-On Serverless Applications with Go, published by Packt.
Stars: ✭ 92 (-66.91%)
Mutual labels:  cloudformation, api-gateway, dynamodb, sam
Serverless Express
Run Node.js web applications and APIs using existing application frameworks on AWS #serverless technologies such as Lambda, API Gateway, Lambda@Edge, and ALB.
Stars: ✭ 4,265 (+1434.17%)
Mutual labels:  api-gateway, aws-lambda, sam, dynamodb
Gofaas
A boilerplate Go and AWS Lambda app. Demonstrates an expert configuration of 10+ AWS services to support running Go functions-as-a-service (FaaS).
Stars: ✭ 731 (+162.95%)
Mutual labels:  aws-lambda, cloudformation, sam
Aws Iot Chat Example
💬 Chat application using AWS IoT platform via MQTT over the WebSocket protocol
Stars: ✭ 474 (+70.5%)
Mutual labels:  aws-lambda, dynamodb, amazon-cognito
cfn-api-gateway-custom-domain
API Gateway custom domains as CloudFormation resources, backed by Let's Encrypt
Stars: ✭ 17 (-93.88%)
Mutual labels:  cloudformation, aws-lambda, api-gateway
Aws Toolkit Eclipse
AWS Toolkit for Eclipse – an open-source plugin for developing, deploying, and managing AWS applications.
Stars: ✭ 252 (-9.35%)
Mutual labels:  aws-lambda, cloudformation, dynamodb
Yoyo
A dead simple comment engine built on top of AWS lambda and React, alternative comment service to Disqus.
Stars: ✭ 210 (-24.46%)
Mutual labels:  api-gateway, aws-lambda, dynamodb
super-serverless-sample
Backend serverless que simula o sistema de votação do BBB
Stars: ✭ 30 (-89.21%)
Mutual labels:  aws-lambda, api-gateway, dynamodb
mangum-cli
CLI tools for use with Mangum
Stars: ✭ 14 (-94.96%)
Mutual labels:  aws-lambda, api-gateway
twitter
A serverless social network that's under development with some cool stuff, such as Serverless Framework, AppSync, GraphQL, Lambda, DynamoDB, Cognito, Kinesis Firehose, and Algolia ☁️
Stars: ✭ 29 (-89.57%)
Mutual labels:  aws-lambda, dynamodb
webpack-aws-lambda
AWS Lambda that runs webpack and output the bundle.js file
Stars: ✭ 12 (-95.68%)
Mutual labels:  aws-lambda, api-gateway
hyper-kube-config
H Y P E R K U B E - A Serverless API and kubectl plugin providing a storage and retrieval Kubernetes cluster credentials. Hyperkube leverages AWS Secrets Manager for storing credential information.
Stars: ✭ 27 (-90.29%)
Mutual labels:  aws-lambda, dynamodb
Serverlessbydesign
A visual approach to serverless development. Think. Build. Repeat.
Stars: ✭ 254 (-8.63%)
Mutual labels:  aws-lambda, cloudformation
demo-serverless-aspnetcore
ASP.Net Core 3.1 on AWS Lambda demo
Stars: ✭ 22 (-92.09%)
Mutual labels:  aws-lambda, api-gateway
nestjs-graphql-serverless
Boilerplate for using NestJS with GraphQL (Code-First) on serverless environment (AWS Lambda)
Stars: ✭ 64 (-76.98%)
Mutual labels:  aws-lambda, api-gateway
lambda-smush-py
Gain additional code space via cheeky compression for Python AWS Lambda functions defined in-line to CloudFormation templates.
Stars: ✭ 17 (-93.88%)
Mutual labels:  cloudformation, aws-lambda
whats-your-name
Sample app for AWS Serverless Repository - uses Amazon Rekognition to recognize person on the photo
Stars: ✭ 17 (-93.88%)
Mutual labels:  cloudformation, aws-lambda
serverless-data-pipeline-sam
Serverless Data Pipeline powered by Kinesis Firehose, API Gateway, Lambda, S3, and Athena
Stars: ✭ 78 (-71.94%)
Mutual labels:  cloudformation, aws-lambda
Aegis
Serverless Golang deploy tool and framework for AWS Lambda
Stars: ✭ 277 (-0.36%)
Mutual labels:  api-gateway, aws-lambda
faaskit
A lightweight middleware framework for functions as a service
Stars: ✭ 24 (-91.37%)
Mutual labels:  aws-lambda, sam

aws-cognito-apigw-angular-auth

A simple/sample AngularV4-based web app that demonstrates different API authentication options using Amazon Cognito and API Gateway with an AWS Lambda and Amazon DynamoDB backend that stores user details as part of the blog post https://aws.amazon.com/blogs/compute/secure-api-access-with-amazon-cognito-federated-identities-amazon-cognito-user-pools-and-amazon-api-gateway/ :

Required Tools

Instructions

Get started by cloning the repository then editing some files described with more detail in steps 1-4:

  1. Upload the file "sam/lambda.zip" to a S3 bucket of choice and add the bucket details to the "sam/sam.yaml" SAM Template (Resources->CognitoDemoFunction->Properties->CodeUri). The bucket should be in the same region as all resources.

  2. Package the template with the following command and execute the resulting 'aws cloudformation deploy' output using the AWS CLI:

aws cloudformation package --template-file sam.yaml --output-template-file sam-output.yaml --s3-bucket <bucket>

The next command should be something similar to:

aws cloudformation deploy --template-file /Users/<username>/GitHub/aws-cognito-apigw-angular-auth/sam/sam-output.yaml --stack-name CognitoAPIGWDemo --capabilities CAPABILITY_IAM

CloudFormation will automatically create and configure the following resources in your account:

  • Cognito User Pool, including app client and group
  • Cognito Identity Pool
  • Cognito IAM Roles for User Pools group and Identity Pool Authentication Provider
  • API Gateway API
  • Lambda Function
  • DynamoDB Table

After the stack completes, the following command will show you the Outputs:

aws cloudformation describe-stacks --query 'Stacks[0].[Outputs[].[OutputKey,OutputValue]]|[]' --output text --stack-name CognitoAPIGWDemo
  1. Generate a Google API ID following the instructions on http://docs.aws.amazon.com/cognito/latest/developerguide/google.html

  2. Either refer to the output of the "describe-stacks" command above or go to the CloudFormation console, select the stack created on item 2 and open the OUTPUTS tab. All resources we'll need will be there. Use the information to fill up the details under RESOURCE IDENTIFIERS of the file "src/app/aws.service.ts" including the region.

  3. Go to the Cognito Console, select the Identity Pool created by CloudFormation under FEDERATED IDENTITIES and click on EDIT IDENTITY POOL.

  4. Go to the AUTENTICATION PROVIDERS section, select the tab GOOGLE+, click on the UNLOCK button and add the details on the Google API ID generated on step 4. Save the changes.

  5. Click on EDIT IDENTITY POOL once more, go to the AUTENTICATION PROVIDERS section, select the COGNITO tab. Under AUTHENTICATED ROLE SELECTION select the option CHOSE ROLE FROM TOKEN and under ROLE RESOLUTION select DENY. Save the changes.

  6. Create 2 users on your User Pool using a command similar to the AWS CLI command bellow for both of them then confirm the user in the Cognito User Pools console:

aws cognito-idp sign-up \
--client-id <<App Client ID>> \
--username jdoe \
--password [email protected] \
--region <<region>> \
--user-attributes '[{"Name":"given_name","Value":"John"},{"Name":"family_name","Value":"Doe"},{"Name":"email","Value":"[email protected]"},{"Name":"gender","Value":"Male"},{"Name":"phone_number","Value":"+61XXXXXXXXXX"}]'
  1. Add one of the users to the group called "cip-group" in the Cognito User Pool

  2. Create a new "aws-cognito-apigw-angular" project folder by executing the following commands from a terminal in a host on which you want to run the application:

npm install -g @angular/[email protected]
ng new aws-cognito-apigw-angular
cd aws-cognito-apigw-angular
aws apigateway get-sdk --rest-api-id <RestApiId from CloudFormation OUTPUTS> --stage-name demo --sdk-type javascript apigwsdk.zip
unzip apigwsdk.zip

(If you are using Windows skip the last command and unzip the SDK file manually)

  1. Update the project folder:
  • Remove the default "src" folder generated by the previous step
  • Copy the updated "src" folder that contains the modified "aws.service.ts" file from step 4 into the new project directory created in the previous step
  • Overwrite the default "package.json" file generated in the new project folder with the one saved in this repo
  1. From the new folder "aws-cognito-apigw-angular" execute the following commands in a terminal:
npm install 
npm start
  1. Access http://localhost:4200/ in a browser then log in with the user above

  2. Authentication should now work as:

  • The Google authenticated user should only be able to access the API resource /google
  • The Cognito User Pools user member of the group "cip-group" should only be able to access the API resource /cip
  • The Cognito User Pools user without any group membership should only be able to access the API resource /cup

License Summary

This sample code is made available under the MIT-0 license. See the LICENSE file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].