Real-Dev-Squad / feature-flag-backend

This is the repository for Feature flag service.
MIT License
4 stars 4 forks source link

Instructions for deploying for staging #118

Open MehulKChaudhari opened 1 month ago

MehulKChaudhari commented 1 month ago

Steps to deploy for staging

Note: Please use a different region than production so it interacts with the correct DB.

  1. Create a DB for staging.

    Tables in DynamoDB

    featureFlag

    Partition Key - id (string)

    featureFlagUserMapping

    Partition Key - userId (string) Sort Key - flagId (string)

    requestLimit

    Partition Key - limitType (String)

    no sort key here

Note Indexes are not required

  1. log in with the administrator AWS account in AWS CLI. Then clone the feature flag backend project (https://github.com/Real-Dev-Squad/feature-flag-backend) and run sam pipeline init --bootstrap. https://www.youtube.com/watch?v=jBCf8g7VXhw This video will guide you with the command specifics (Just for reference).

Steps after running sam pipeline init --bootstrap

After completing the command setup, you already created a user in your AWS whose AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are displayed on your screen.

After completion of this, it displays the stack name, pipeline Execution Role, Cloud Formation Execution Role, artifact Bucket. Use all in actions env's.

Update the keys you got in the Github secrets.

Permission to add:

  1. Create a policy Named: feature-flag-lambda-db-role and Add this policy to all the Lambda's as it update values in DB and invokes rate limiter lamda.
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "dynamodb:BatchGetItem",
                "dynamodb:GetItem",
                "dynamodb:Query",
                "dynamodb:Scan",
                "dynamodb:BatchWriteItem",
                "dynamodb:PutItem",
                "dynamodb:UpdateItem"
            ],
            "Resource": "arn:aws:dynamodb:us-east-1:181388287005:table/*"
        },
        {
            "Effect": "Allow",
            "Action": [
                "logs:CreateLogStream",
                "logs:PutLogEvents"
            ],
            "Resource": "arn:aws:logs:us-east-1:181388287005:*"
        },
        {
            "Effect": "Allow",
            "Action": "logs:CreateLogGroup",
            "Resource": "arn:aws:logs:us-east-1:181388287005:*"
        },
        {
            "Sid": "InvokePermission",
            "Effect": "Allow",
            "Action": [
                "lambda:InvokeFunction"
            ],
            "Resource": "arn:aws:lambda:us-east-1:181388287005:function:feature-flag-staging*"
        }
    ]
}
  1. Add this policy to Rate Limiter and Reset Limit Lambda roles:
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": [
                "lambda:PutFunctionConcurrency",
                "lambda:DeleteFunctionConcurrency"
            ],
            "Resource": "arn:aws:lambda:us-east-1:181388287005:function:feature-flag-staging*"
        }
    ]
}

As we change the concurrency of the other Lamda's when limit is reached to close the lambda's and reset the limit and start all the lambda's again.

Things to do:

prakashchoudhary07 commented 2 weeks ago

@MehulKChaudhari

In between setup, you are asking to watch a YouTube video of 25 minutes to do the setup. Can you please mention all the steps required in the issue itself? I don't want to watch the YouTube video here that is 25 minutes long

MehulKChaudhari commented 2 weeks ago

@MehulKChaudhari

In between setup, you are asking to watch a YouTube video of 25 minutes to do the setup. Can you please mention all the steps required in the issue itself? I don't want to watch the YouTube video here that is 25 minutes long

@prakashchoudhary07 Sir, That video is for reference. I will make it better till tomorrow and get back to you.