Storage, Auth & Database

This section covers Steps 8–12: creating the S3 bucket, Amazon Cognito user pool, SQS queues, SSM Parameter Store, and the RDS PostgreSQL database.


Step 8: Create S3 Bucket

Console: S3 → Create bucket

FieldValue
Bucket namesmart-invoice-shield-storage
Regionap-southeast-1
Block all public accessBlock all
Default encryptionSSE-S3

[!CAUTION] Do NOT enable public access. Invoice files are accessed only via Presigned URLs.


Step 9: Create Amazon Cognito

9.1 Create User Pool

Console: Cognito → Create user pool

FieldValue
Application typeTraditional web application
App client namesmart-invoice
Sign-in identifiersEmail
Self-registration✅ Enable
Required attributesemail

alt text

9.2 Add Custom Attributes

User Pool → Authentication → Sign-up → Add custom attributes:

  • company_id (String)
  • role (String)

→ Save

alt text

9.3 Enable Password Auth

App clients → smart-invoiceEdit → ✅ ALLOW_USER_PASSWORD_AUTHSave

alt text

9.4 Note Down Credentials

InformationWhere to find
User Pool IDOverview (ap-southeast-1_XXX)
Client IDApp clients
Client SecretApp clients → Show

Step 10: Create SQS Queues

Queue 1: OCR Queue

Console: SQS → Create queue

FieldValue
TypeStandard
Namesmartinvoice-ocr-queue
Visibility timeout450 seconds
Receive message wait time20 seconds

alt text

Queue 2: VietQR Queue

FieldValue
TypeStandard
Namesmartinvoice-vietqr-queue
Visibility timeout30 seconds
Receive message wait time20 seconds

→ Note down the Queue URL for both queues.


Step 11: Create SSM Parameter Store

Console: Systems Manager → Parameter StoreCreate parameter

Parameter NameTypeValue
/SmartInvoice/prod/COGNITO_USER_POOL_IDString(from Step 9)
/SmartInvoice/prod/COGNITO_CLIENT_IDString(from Step 9)
/SmartInvoice/prod/COGNITO_CLIENT_SECRETSecureString(from Step 9)
/SmartInvoice/prod/AWS_SQS_OCR_URLString(Step 10 — OCR queue URL)
/SmartInvoice/prod/AWS_SQS_URLString(Step 10 — VietQR queue URL)
/SmartInvoice/prod/POSTGRES_HOSTString(Step 12 — RDS endpoint)
/SmartInvoice/prod/POSTGRES_PORTString5432
/SmartInvoice/prod/POSTGRES_DBStringSmartInvoiceDb
/SmartInvoice/prod/POSTGRES_USERStringpostgres
/SmartInvoice/prod/POSTGRES_PASSWORDSecureString(RDS password)
/SmartInvoice/prod/AWS_REGIONStringap-southeast-1
/SmartInvoice/prod/AWS_S3_BUCKET_NAMEStringsmart-invoice-shield-storage
/SmartInvoice/prod/OCR_API_ENDPOINTStringhttp://<ALB_OCR_DNS> (update after Step 14.4)
/SmartInvoice/prod/ALLOWED_ORIGINSString(update after Step 17)

Step 12: Create RDS PostgreSQL

12.1 Create DB Subnet Group

Console: RDS → Subnet groupsCreate

FieldValue
Namesmartinvoice-db-subnet-group
VPCsmartinvoice-vpc
SubnetsBoth private subnets (1a + 1b)

12.2 Create Database

Console: RDS → DatabasesCreate database

FieldValue
EnginePostgreSQL 16.x
Creation methodFull configuration
TemplateFree tier / Dev-Test
Deployment optionsMulti-AZ DB instance deployment
DB identifiersmartinvoice-db
Master usernamepostgres
Credentials managementSelf managed
Master password[YOUR_SECURE_PASSWORD]
Instance classdb.t3.micro
Storage20 GB gp3
VPCsmartinvoice-vpc
Subnet groupsmartinvoice-db-subnet-group
Public access❌ No
Security groupsmartinvoice-rds-sg
Initial DB nameSmartInvoiceDb
Backup retention7 days

alt text alt text

→ Wait 5–10 minutes → Note down the Endpoint → Update SSM parameter POSTGRES_HOST.