To invoke our API’s, we first need to fetch the ApiUrl
output variable that our CloudFormation 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 sam-app --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": "Sample test item"
}'
curl -X POST \
$ApiUrl/items/ \
-d '{
"id":"2",
"name": "Second test item"
}'
Get All Items
operationcurl -X GET $ApiUrl/items/ | jq
Get Item by Id
operationcurl -X GET $ApiUrl/items/1 | jq