#!/bin/bash # variables TEMPLATE_IN=sam_template.yaml TEMPLATE_OUT=template-packaged.yaml S3_BUCKET=serverless-sam-demos STACK_NAME=ServerlessSAMDemo REGION=eu-west-1 # package (upload artifact to S3) echo "SAM is now packaging..." sam package --template-file $TEMPLATE_IN --s3-bucket $S3_BUCKET --output-template-file $TEMPLATE_OUT --region $REGION # deploy (CloudFormation changesets) echo "SAM is now deploying..." sam deploy --template-file $TEMPLATE_OUT --stack-name $STACK_NAME --capabilities CAPABILITY_IAM --region $REGION # fetch and show CloudFormation output ENDPOINT=$(aws cloudformation describe-stacks --stack-name $STACK_NAME --region $REGION --query 'Stacks[0].Outputs[?OutputKey==`ENDPOINT`].OutputValue' --output text) echo "ENDPOINT: $ENDPOINT"