Giter Site home page Giter Site logo

globebyte / aws-sam-movies-api-resource-policy Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aws-samples/aws-sam-movies-api-resource-policy

0.0 1.0 0.0 12 KB

SAM Template with Lambda Function to spin up a DynamoDB backed Movies API and attach APIGW Resource Policy to it.

License: MIT No Attribution

Python 100.00%

aws-sam-movies-api-resource-policy's Introduction

SAM Movies API & Resource Policy

SAM Template with Lambda Function to spin up a DynamoDB backed Movies API and Resource Policy to be attached to it.

License Summary

This sample code is made available under a modified MIT license. See the LICENSE file.

AM Movies API with APIGW Resource Policies

Pre-Requisites:

aws-cli/1.15.0, jq-1.5, perl v5.18.2, python2.7

Fill in the following variables first and set as Env Vars

#AWS Region where your API is deployed
REGION=""
#AWS Account who will access your API
AccountA=""
#AWS Account where your API is hosted
AccountB=""
#User in Account A who will access your API
userA=""
#S3 Bucket where the SAM templates will live
S3Bucket=""

Build and Deploy the movies API

mkdir ./build
cp -p -r ./movies ./build/movies
pip install -r requirements.txt -t ./build

aws cloudformation package --template-file template.yaml --output-template-file template-out.yaml --s3-bucket $S3Bucket

aws cloudformation deploy --template-file template-out.yaml --stack-name apigw-resource-policies-demo --capabilities CAPABILITY_IAM

Get API ID after deployment

API_ID=$(aws cloudformation describe-stacks --stack-name apigw-resource-policies-demo --query 'Stacks[0].Outputs[?OutputKey==`AwsApiId`].OutputValue' --output text)

Create APIGW Resource Policy from template

cp policy.json_template policy.json

perl -p -i -e "s/account_idA/$AccountA/g" policy.json
perl -p -i -e "s/account_idB/$AccountB/g" policy.json
perl -p -i -e "s/region/$REGION/g" policy.json
perl -p -i -e "s/api_id/$API_ID/g" policy.json
perl -p -i -e "s/user/$userA/g" policy.json

policy=`cat policy.json`

Apply the resource policy to the API

aws apigateway update-rest-api --rest-api-id $API_ID --patch-operations op=replace,path=/policy,value="$policy"

aws-sam-movies-api-resource-policy's People

Contributors

jpeddicord avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.