Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.