AWS Aurora RDS Cluster restore using Lambda function - SAM Template example

Automating database refresh in AWS. Creating a AWS Lambda function which restores AWS Aurora RDS Cluster will need some configuration and Policies to get and run a restore from a previously generated snapshot. The following code snippet is an YAML example configuration for creating a AWS Lambda function with AWS SAM. Adding the code to the AWS SAM template file under ‘Resources’ will create this function with code. RestoreClusterFunction: Type: AWS::Serverless::Function Properties: CodeUri: functions/restore_cluster/ Handler: app.lambda_handler Runtime: python3.9 Architectures: - x86_64 Environment: Variables: DBClusterIdentifier: !Ref DatabaseClusterName Policies: - Statement: - Effect: Allow Action: - 'rds-data:ExecuteStatement' - 'rds:DescribeDBClusters' - 'rds:RestoreDBClusterFromSnapshot' Resource: !Sub 'arn:aws:rds:${AWS::Region}:${AWS::AccountId}:cluster:${DatabaseClusterName}' - Effect: Allow Action: - 'rds:DescribeDBSnapshots' - 'rds:RestoreDBClusterFromSnapshot' Resource: - !Sub 'arn:aws:rds:${AWS::Region}:${AWS::AccountId}:snapshot:*' - !Sub 'arn:aws:rds:${AWS::Region}:${AWS::AccountId}:cluster-pg:*' # Or specific group name - !Sub 'arn:aws:rds:${AWS::Region}:${AWS::AccountId}:cluster-snapshot:*' - !Sub 'arn:aws:rds:${AWS::Region}:${AWS::AccountId}:subgrp:*' - Effect: Allow Action: - 'kms:CreateGrant' - 'kms:DescribeKey' Resource: !Sub 'arn:aws:kms:${AWS::Region}:${AWS::AccountId}:key/{key_id}' # Replace {key_id} with the AWS id of the KMS key.

July 19, 2022

How to chose between SQS vs SNS vs Eventbridge

SQS Queues Queues are places where you send and from where applications are consuming messages. A message can stay in the queue until it is consumed or a timeout occurs. Timeout periods are configurable. Messages Messages are the content or the payload of the data that is send to the queue which needs to be processed by other services or applications. Usually the format of a message is in JSON format. ...

July 14, 2022