#!/usr/bin/env bash set -e
export RAILS_ENV=${RAILS_ENV:=“production”} export AWS_DEFAULT_REGION=${AWS_DEFAULT_REGION:=us-east-1} export CLOUDFORMATION_BUCKET=${CLOUDFORMATION_BUCKET:=“lamby.cloudformation.$(whoami)”}
./bin/build
export VPCID=${VPCID:=$(
aws ec2 describe-vpcs \ --output text \ --filters 'Name=state,Values=available' \ --query 'Vpcs[0].VpcId'
)}
export SUBNETS=${SUBNETS:=$(
aws ec2 describe-subnets \ --output text \ --filters "Name=state,Values=available,Name=vpc-id,Values=$VPCID" \ --query 'Subnets[*].SubnetId' | \ tr -s '[:blank:]' ','
)}
sam package \
--region ${AWS_DEFAULT_REGION} \ --template-file ./.aws-sam/build/template.yaml \ --output-template-file ./.aws-sam/build/packaged.yaml \ --s3-bucket $CLOUDFORMATION_BUCKET \ --s3-prefix "APPNAMEHERE-${RAILS_ENV}"
sam deploy \
--template-file ./.aws-sam/build/packaged.yaml \ --stack-name "APPNAMEHERE-${RAILS_ENV}-${AWS_DEFAULT_REGION}" \ --capabilities "CAPABILITY_IAM" \ --parameter-overrides \ RailsEnv=${RAILS_ENV} \ VpcId=${VPCID} \ Subnets=${SUBNETS}