STAC 2023 lambdas and other architecture deployed and managed by Terraform
-
Install AWS CLI
-
Install Terraform
-
Create Access Keys for your AWS user
- In console type
aws configure
- Enter your AWS Access Key
- Enter your AWS Secret Key
- In console type
-
You will have to set up remote state storage for Terraform, you can use Amazon S3 and Amazon DynamoDB as the backend storage for your Terraform state. Here's how you can set it up:
- Create an S3 bucket: Start by creating an S3 bucket in AWS that will be used to store the Terraform state file.
- Go to the AWS Management Console and navigate to the S3 service.
- Click on "Create bucket" and provide a unique name for your bucket.
- e.g., terraformstatestorage-stac2023
- Choose the region where you want to create the bucket.
- e.g., us-east-1
- Configure the bucket settings as per your requirements, such as enabling versioning or enabling server-side encryption.
- Keep note of the bucket name as you'll need it in the next steps.
- Create a DynamoDB table: Next, create a DynamoDB table to be used as a locking mechanism for Terraform state.
- Go to the AWS Management Console and navigate to the DynamoDB service.
- Click on "Create table" and provide a unique name for your table.
- Set the partition key attribute name to LockID.
- Enable auto scaling if desired and configure other settings as per your needs.
- Create the table and remember the table name
- e.g., terraformstatedb-stac2023
- Configure Terraform backend: In your Terraform configuration files, specify the backend configuration to use S3 and DynamoDB for remote state storage.
- Open your Terraform configuration file (e.g., main.tf) in a text editor.
- Add the following code snippet to configure the backend (should be placed towards the top of the file, preferrably right after the provider section):
terraform { backend "s3" { bucket = "your-bucket-name" key = "path/to/your/terraform.tfstate" region = "aws-region" dynamodb_table = "your-dynamodb-table-name" } }
- Based on the example values provided above, your snippet will look like this:
terraform { backend "s3" { bucket = "terraformstatestorage-stac2023" key = "terraformstate/terraform.tfstate" region = "us-east-1" dynamodb_table = "terraformstatedb-stac2023" } }
- Initialize Terraform: After configuring the backend, initialize Terraform to set up the remote state storage.
- Open a terminal or command prompt and navigate to the directory containing your Terraform configuration files.
- Run the terraform init command. Terraform will initialize the backend and download the necessary provider plugins.
- Apply Terraform changes: Once the backend is configured and initialized, you can proceed with applying changes to your infrastructure using Terraform.
- Run the terraform apply command in your Terraform directory to create or update the resources defined in your configuration.
Now, Terraform will use the specified S3 bucket and DynamoDB table for remote state storage. Each time you run Terraform commands, it will read and write the state to the configured S3 bucket, and leverage the DynamoDB table for state locking to ensure safe concurrent access.
- Create an S3 bucket: Start by creating an S3 bucket in AWS that will be used to store the Terraform state file.
-
Run the deploy script by entering
./deploy.sh
- Follow any feedback from the script to get going or read on below
- You need a variables.tf file in your root directory that looks similar to:
variable "region" { default = "us-east-1" } variable "OPENAI_API_KEY" { type = string default = "ENTER_OPENAI_API_KEY_HERE" }'
- NOTE: variables.tf is where all the lambda environment variables will be stored, never commit to repo.
- The command to deploy your terraform is
./deploy.sh terraform
- The command to deploy a lambda function is
./deploy.sh terraform 'lambda_function_name'
- Example:
./deploy.sh terraform fileUploaded
- Example:
-
Make updates on a feature branch
-
Please create a PR and have one Approval before merging code