Pre-requisites:
- AWS Account
- Mailchimp Account
- Domain to connect Emails
- AWS CLI
- MongoDB Instance (You can use Free tier of MongoAtlas)
- AWS Amplify CLI
- Clone: https://github.com/FlavioAandres/FinancesApp
Install with npm i @aws-amplify/cli -g
We’re using amplify to deploy our Cognito user pool automatically, also, the frontend (client) is working through the Cognito Authentications using Cognito API and package.
- Run
cd client/ && amplify init
- Try to get something similar to this in the wizard:
- Add the authentication using API Key or Profiles, I'm gonna use APIKEY, this operation will create new IAM Resources to allow Amplify do stuffs
- Once the environment is initialized, run
cd client/ && amplify add auth
, and continue the wizard according to these settings.
- After the previous step, confirm the file
./src/aws-exports.json
is located on the root of/client
- Now, let’s deploy the authentication to AWS running
amplify push
and confirm when the CLI asks for confirmation
- Feel free and happy if you see the following message after deploying:
I recommend you go to AWS Console (web dashboard) and check the new Cognito User Pull is successfully deployed as this:
Initializing the UI in local to connect with the current user pool (testing everything goes properly)
- run
npm install
,thennpm run start
you must see no error in the React Client
To create an account, for the first time, we need to continue deploying and configuring the API to save the users created by Cognito, so, let’s deploy the API.
- IMPORTANT!!! - Run
aws configure
and set your credentials. thanks Oswaldo to deploy everything in the Business account and realized this. - Go to the root of the Project and create a new filed called:
config/{environment}.json
with the following fields:
-- ./config/test.json
{
"MONGO_HOST": "YourMongoDB_Host",
"MONGO_PORT": 27017,
"MONGO_SECRET": "MongoPass",
"MONGO_SET": "replica-set-Cluster0-shard-0",
"MONGO_USER": "MongoUSER",
"MONGO_DATABASE":"DatabaseName",
"SRV_CONFIG": false,
"USER_POOL_ARN": "arn:aws:cognito-idp:us-east-1:9999999999:userpool/us-west-1_632zAiS9C"
}
The fields above show all the environment vars needed by the API, basically the MONGO and COGNITO credentials.
- run
cd ../
npm install
- run
serverless deploy --stage {environment} --region={same_as_cognito_region}
If everything is successfully deployed, you must see something similar to the logs above.
- Go to your Cognito user Pool → Triggers → Set the function for Post Confirmation hook.
- Click on “Save”
- Create an S3 Bucket with the Website property in the AWS Console
- If you already have a domain name for this, remember to name the Bucket with the domain address, for example for the name: finances.flavioaandres.com. These are the steps to create:
- After creating the S3 bucket, go to the bucket and Click on Properties
- Enable the Static Web Hosting feature and add the following settings:
- Index page: index.html
- Error Page: index.html
- Go to
./client/package.json
and update the following scripts to point to your S3 bucket name instead of flavioaandres.com 🙂- deploy:test
- deploy:prod
- example:
"npm run build:test && aws s3 sync build/ s3:**//my-finances-bucket-flavio** --acl public-read",
- Check your
.env.{environment}
is created, if you’re going to deploy test stage, check.env.test
is set up with the right .env vars:
REACT_APP_FINANCES_API_URL="https://api.env.flavioaandres.com"
- Now, run to deploy:
cd client/ && npm run deploy:test
- Create the Mail-chimp account and then click on Transactional Email and Launch App
- Add your own domain and follow the instructions of mailchimp setup
- Create the email where you will receive the messages and test it
{
"_id" : ObjectId("5fd625d50e1f299d3a6c9521"),
"filters" : [
{
"phrase" : "Bancolombia te informa recepción transferencia",
"type" : "INCOME",
"parser" : "transferReception"
},
{
"phrase" : "Bancolombia le informa Compra",
"type" : "EXPENSE",
"parser" : "shopping"
},
{
"phrase" : "Bancolombia le informa Retiro",
"type" : "EXPENSE",
"parser" : "debitWithdrawal"
},
{
"phrase" : "Bancolombia le informa Transferencia",
"type" : "EXPENSE",
"parser" : "transfer"
},
{
"phrase" : "Bancolombia le informa Pago",
"type" : "EXPENSE",
"parser" : "payments"
}
],
"name" : "BANCOLOMBIA",
"subjects" : [
"Servicio de Alertas y Notificaciones Bancolombia",
"Servicio de Alertas.",
"Servicio de Alertas y Notificaciones",
"Alertas y Notificaciones"
],
"folder" : "INBOX",
"createdAt" : ISODate("2020-11-26T19:32:15.925Z"),
"updatedAt" : ISODate("2020-11-26T19:32:15.925Z"),
"__v" : 0.0,
"ignore_phrase" : "Bancolombia le informa que su factura inscrita",
"index_value" : NumberLong(0)
}