Skip to content

Instantly share code, notes, and snippets.

@michimani
Created February 17, 2020 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save michimani/a98f90960ac497e370c5a2eecb68d7a9 to your computer and use it in GitHub Desktop.
Save michimani/a98f90960ac497e370c5a2eecb68d7a9 to your computer and use it in GitHub Desktop.
A CloudFormation template for creating API Gateway usage plan.
AWSTemplateFormatVersion: "2010-09-09"
Description: "API Gateway - usage plan template."
Parameters:
TargetApiId:
Type: String
Resources:
UsagePlan:
Type: "AWS::ApiGateway::UsagePlan"
Properties:
ApiStages:
- ApiId: !Ref TargetApiId
Stage: api
Description: Usage plan for API
UsagePlanName: ApiUsagePlan
Outputs:
UsagePlanID:
Description: ID of created usage plan
Value: !Ref UsagePlan
#!/bin/bash
CHANGESET_OPTION="--no-execute-changeset"
if [ $# = 1 ] && [ $1 = "deploy" ]; then
echo "deploy mode"
CHANGESET_OPTION=""
fi
CFN_TEMPLATE="$(dirname $0)/api-usage-plan.yml"
CFN_STACK_NAME=ApiUsagePlan
aws cloudformation deploy --stack-name ${CFN_STACK_NAME} --template-file ${CFN_TEMPLATE} --parameter-overrides ChaliceDeployedApi=${TARGET_API_ID} ${CHANGESET_OPTION}
if [ $# = 1 ] && [ $1 = "deploy" ]; then
echo "\n----------------------------------------------\n"
echo "Following string is ID of created usage plan. Use it for creating api key belongs to an usage plan.\n"
aws cloudformation describe-stacks --stack-name ${CFN_STACK_NAME} | jq ".Stacks[0].Outputs[0].OutputValue" | sed -E "s/\"//g"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment