Go back to your Cloud9 environment and open a terminal tab.
To invoke our API’s, we first need to fetch the ApiUrl
output variable that our CloudFormation Development stack gives us. So let us iterate through our stack and export all output variables as environment variables.
export ApiUrl=$(aws cloudformation describe-stacks --stack-name demo-service-Dev --output json | jq '.Stacks[].Outputs[] | select(.OutputKey=="ApiUrl") | .OutputValue' | sed -e 's/^"//' -e 's/"$//')
echo "export ApiUrl="$ApiUrl
Put Item
operationcurl -X POST \
$ApiUrl/items/ \
-d '{
"id":"1",
"name": "Development Test Item"
}'
Get Item by Id
operationcurl -X GET $ApiUrl/items/1 | jq
Your expected output should be:
{"id":"1","name":"Development Test Item"}
Let’s override our environment variables with the values from the Production stack.
export ApiUrl=$(aws cloudformation describe-stacks --stack-name demo-service-Prod --output json | jq '.Stacks[].Outputs[] | select(.OutputKey=="ApiUrl") | .OutputValue' | sed -e 's/^"//' -e 's/"$//')
echo "export ApiUrl="$ApiUrl
Get Item by Id
operationLet’s first make sure that we are calling a different endpoint return different data.
curl -X GET $ApiUrl/items/1 | jq
Your expected output should be:
{}
Put Item
operationcurl -X POST \
$ApiUrl/items/ \
-d '{
"id":"1",
"name": "Production Test Item"
}'
Get Item by Id
operation againcurl -X GET $ApiUrl/items/1 | jq
Your expected output should be:
{"id":"1","name":"Production Test Item"}