Deploy an endpoint which will tell you what time is in the timezone you code in index.js file. You will be able to navigate to the url endpoint and you will get the time.
Requirements:
Instructions:
- Clone this repo and cd into it
git clone https://github.com/s4nt14go/helloSam.git
- Check your are using your AWS credentials and the region you want
aws configure list
- Create a bucket filling with a random suffix (because the name has to be unique), for example if we want to deploy in region us-east-2 Ohio:
aws s3 mb s3://lambda-deployment-artifacts-<yourRandomSuffix> --region us-east-2
- We will first build the project locally and then deploy it, so
cd
into the repo. As the runtime specified in template.yml is node v12 we have to use the same version locally, so make sure you are using node v12 runningnode -v
. If you aren't using v12 you can use nvm to install and set node v12 as the current node version. - Build the project locally
sam build
- Check it works locally
sam local invoke TimeFunction
- Deploy it!
sam deploy --stack-name myStack --s3-bucket lambda-deployment-artifacts-<yourRandomSuffix> --capabilities CAPABILITY_IAM --region us-east-2
The last comand will output an url similar to
https://<randomChars>.execute-api.us-east-2.amazonaws.com/prod/TimeResource
visit it with your browser and you will get the time from the timezone set in index.js.
You can try changing tz
value in index.js for the timezone of your choice according to moment-timezone and repeat steps 5, 6 and 7.
As a demo you can browse to the endpoint this repo deploys:
https://hmddi9jmv3.execute-api.us-east-1.amazonaws.com/prod/TimeResource