Script

We need some values that are not known before deployment. We will use the sls info -v command to get the actual values that we need to configure the frontend. Create a bash script to add the necessary deployment functions. First, we need an extract function to get the second column aster space delimited of sls info output:

extract() {
echo "$DATA" | grep $1 | cut -d " " -f2
}

To deploy an application with the Serverless Framework, you have to call the sls deploy command, but our application is more complex and we have to use a sequence of commands:

deploy() {
echo "ASSETS DOWNLOADING"
curl -L https://api.github.com/repos/aws-samples/aws-serverless-workshops/tarball
| tar xz --directory assets --wildcards "*/WebApplication/1_StaticWebHosting/website" --strip-components=4
echo "LAMBDAS BUILDING"
sls deploy
echo "ASSETS UPLOADING"
sls client deploy
echo "CONFIGURATION UPLOADING"
DATA=`sls info -v`
POOL_ID=`extract PoolId`
POOL_CLIENT_ID=`extract PoolClientId`
REGION=`extract region`
ENDPOINT=`extract ServiceEndpoint`
CONFIG="
window._config = {
cognito: {
userPoolId: '$POOL_ID',
userPoolClientId: '$POOL_CLIENT_ID',
region: '$REGION'
},
api: {
invokeUrl: '$ENDPOINT'
}
};
"
echo "$CONFIG" | aws s3 cp - s3://rust-sls-aws/js/config.js
INDEX=`extract BucketURL`
echo "INDEX: $INDEX"
}

In the deploy function we download the frontend part of the Wild Rydes application from GitHub and only extract the folder we need to the assets folder of our project. Then we call sls deploy to deploy a stack of the application. Then we call sls client deploy to publish all assets to S3. When all parts are deployed we use the extract function to get all the necessary values to fill the config.js file, which is necessary to connect the deployed frontend with our lambda implemented with Rust. We construct a config.js file from the embedded template and upload it with the aws s3 cp command.

Let's run this command.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.188.218.157