Skip to content

GreenTurtleTech/image-service

Repository files navigation

Image Service

Creates infrastructure for uploads to s3 and sending them to tree-tracker-web. Also has the Lambda function code.

  • When a file is uploaded to /unituploads in the bucket,
    • Lambda function checks if this item has been processed
      • It checks if a file with the same name, but unituploads replaced with processed and with a .json file ending added on. If so, it stops running.
    • Gets the meta data from the s3 object
    • Sends that to tree tracker API
    • Creates a JSON file with the same name, but unituploads replaced with processed and with a .json file ending added on.
      • This file contains the metadata.
      • That way if it doesn't end up saved in the tree tracker, we have it.
  • If you change any of the infrastruture, or the trigger function:
    • If you commit the change to the staging branch, the staging environment will update.
    • If you commit the chnage to the main branch, the production environment will update.

Observing

Cloudwatch Logs

The Lambda function writes logs to Cloudwatch

Environment Variables

The following environment variables are used in the image-service.ts file:

Variable Name Description
ACCOUNT_ID The AWS account ID to deploy the stack to. If not set, the default value is '163934172718'.
AWS_REGION The AWS region to deploy the stack to. If not set, the default value is 'eu-west-2'.
BUCKET_NAME The name of the S3 bucket to create for production images. If not set, the default value is 'protect-earth-prod-photos-58374'.
BUCKET_NAME_STAGING The name of the S3 bucket to create for staging images.
ERRORS_EMAIL The email address to send error notifications to.
TREE_API_URL The URL of the Tree API to use.
TREE_API_URL_STAGING The URL of the staging tree API to use
TREE_API_TOKEN The bearer token for production
TREE_API_TOKEN_STAGING The bearer token for staging

These environment variables are used to configure the ImageService stack.

Note: TREE_API_URL and TREE_API_URL_STAGING are the URL for the application, the /uploads endpoint will be used.

Deployment

Deployment is automated in Github actions.

  • Deployg to prod:
    • npm run deploy:prod
  • Deploy staging
    • npm run deploy:staging
  • If you have a protect_earth profile in ~/.aws/config
    • --profile=protect_earth

Automated Deployments

  • Push to main branch
    • Deploys to prod
  • Push to any other branch
    • Deploys to staging.

Deployment

Deployment is automated in Github actions. These commands asume you have protect_earth profile in ~/.aws/config. Please update as needed.

  • Deploy to prod:
    • npm run deploy:prod -- --profile=protect_earth
  • Deploy staging
    • npm run deploy:staging -- --profile=protect_earth

Automated Deployments

  • Push to main branch
    • Deploys to prod
  • Push to any other branch
    • Deploys to staging.

Create For New Client

Assumptions

Before beginging, make sure these assumptions are true:

Create New Stack

  • Deploy the first time locally.
    • Setup .env file locally with the .env variables for this client
    • Deploy to staging
      • npm run cdk deploy cdk deploy ImageServiceStackStaging --profile=client-aws-profile
    • Deploy prod as well, if stage deploy worked:
      • npm run cdk deploy cdk deploy ImageServiceStack --profile=client-aws-profile
  • Setup automated deployments
    • @todo
  • In your AWS account there should be IAM users with the names iOsAppUserImageServiceStack and iOsAppUserImageServiceStackStaging
  • Create and download an access key for those users, they are needed in the iOS app.

About

New image service

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published