cognito-custom-email

1.1.6 • Public • Published

Cognito Custom Message Lambda

Lambda responsible for triggering personalized emails by platform. This project uses serverless.

Content

Technologies

Configuration

All configuration values should defined using environment variables. as we are using server-less framework, to automatically define environment variables on deploy, you should put all values in the file .env.yml and the server-less will define thats values on AWS Lambda environment when you run the deploy command.

Secrets

Secrets are injected into your functions using environment variables. By defining variables in the provider section of the serverless.yml you add them to the environment of the deployed function. From there, you can reference them in your functions as well.

So you would add something like:

provider:
  environment:
    A_VARIABLE: ${env:A_VARIABLE}

to your serverless.yml, and then you can add A_VARIABLE to your GitLab Ci variables and it will get picked up and deployed with your function.

For local development, we suggest installing something like dotenv to manage environment variables.

Setting Up AWS

  1. Create AWS credentials including the following inline IAM policy:

    {
        "Statement": [
            {
                "Action": [
                    "apigateway:*",
                    "cloudformation:CancelUpdateStack",
                    "cloudformation:ContinueUpdateRollback",
                    "cloudformation:CreateChangeSet",
                    "cloudformation:CreateStack",
                    "cloudformation:CreateUploadBucket",
                    "cloudformation:DeleteStack",
                    "cloudformation:Describe*",
                    "cloudformation:EstimateTemplateCost",
                    "cloudformation:ExecuteChangeSet",
                    "cloudformation:Get*",
                    "cloudformation:List*",
                    "cloudformation:PreviewStackUpdate",
                    "cloudformation:UpdateStack",
                    "cloudformation:UpdateTerminationProtection",
                    "cloudformation:ValidateTemplate",
                    "lambda:*",
                    "logs:CreateLogGroup",
                    "logs:DeleteLogGroup",
                    "logs:DescribeLogGroups",
                    "logs:DescribeLogStreams",
                    "logs:FilterLogEvents",
                    "logs:GetLogEvents",
                    "s3:CreateBucket",
                    "s3:DeleteBucket",
                    "s3:DeleteBucketPolicy",
                    "s3:DeleteObject",
                    "s3:DeleteObjectVersion",
                    "s3:GetObject",
                    "s3:GetObjectVersion",
                    "s3:ListAllMyBuckets",
                    "s3:ListBucket",
                    "s3:PutBucketNotification",
                    "s3:PutBucketPolicy",
                    "s3:PutBucketTagging",
                    "s3:PutBucketWebsite",
                    "s3:PutEncryptionConfiguration",
                    "s3:PutObject"
                ],
                "Effect": "Allow",
                "Resource": "*"
            }
        ],
        "Version": "2022-02-18"
    }
  2. Set the AWS_SHARED_CREDENTIALS_FILE variable with type file in the GitLab CI/CD settings. Settings > CI/CD > Variables.

  3. Inside it should be:

	aws_access_key_id = <access_key_id>
	aws_secret_access_key = <secret_access_key>
	[staging]
	aws_access_key_id = <access_key_id>
	aws_secret_access_key = <secret_access_key>
	[production]
	aws_access_key_id = <access_key_id>
	aws_secret_access_key = <secret_access_key>

NODE_ENV

Define the current environment. This value will be used to define what email template should be used for each message.

  • Optional
  • String
  • Default: development

COGNITO_ESANAR_SOCIAL_APP_ID

The id used to send an email when the user first login with social network.

  • Required
  • String

Templates

This folder stores the same templates in tree directories

development

Stores templates used in development environment

staging

Store templates used in staging environment

production

Store templates used in production environment

Files to be Created

sonar-project.properties

  • Sets Sonar properties for code inspection

Launch local

  1. $ git clone git@gitlab.com:sanardigital/identidade/cognito-lambdas/custom-message.git.
  2. $ cd <folder-source-code>
  3. $ npm install
  4. Set up your aws credentials on your OS. You may need to install aws-cli first. It will be necessary in case of manually deploying the project.
  5. $ clear && npm run dev Execute local. This is for debugging and tests purpose.
  6. You did it, you are great!! Enjoy! 🚀

Scripts

Running

  • $ npm run dev

Testing

  • $ npm run test

  • $ npm run test:debug

Linting

  • $ npm run lint

  • $ npm run lint:fix

Deploying - Not recommended

  • $ npm run deploy:staging

  • $ npm run deploy:production

Project dependencies

Tips

  • Without AWS credentials you will not be able to deploy the project
  • Before each git commit the lint will be run.
  • Before each git push the unit tests will be run.
  • This project uses clean architecture, so it'll be easy to understand folder structure and project organization if you have previous knowledge about this architecture.

Contribuitors

Time Identidade tech.id@sanar.com \

License

(c) Not a free software

Readme

Keywords

none

Package Sidebar

Install

npm i cognito-custom-email

Weekly Downloads

0

Version

1.1.6

License

none

Unpacked Size

534 kB

Total Files

71

Last publish

Collaborators

  • sanar