1回答
- 新しい順
- 投票が多い順
- コメントが多い順
0
⚡I'm updating my response because I missed the tag for Step Function, Lambda, and SNS, and didn't consider using serverless services.
Detailed Architecture Diagram Description
Here's a basic flow:
- External Event trigger the workflow in AWS Step Functions.
- Lambda function sends an approval request via SES.
- Lambda function checks DynamoDB for approvals.
- Once approvals are confirmed, another Lambda function performs the snapshot.
- Workflow completes.
ℹ️ You would need to write AWS Lambda functions for several parts of the process: sending the approval requests, handling the approval reception, checking if both approvals have been received, and taking a snapshot.
Send Approval Requests Lambda Function
import boto3 from urllib.parse import quote_plus def generate_approval_url(approval_lambda_url, user_id): return f"{approval_lambda_url}?response=approve&user_id={quote_plus(user_id)}" def lambda_handler(event, context): ses = boto3.client('ses') approval_lambda_url = 'https://your-api-gateway-url' approvers = { 'User1': 'user1@example.com', 'User2': 'user2@example.com', } for user_id, email in approvers.items(): approval_url = generate_approval_url(approval_lambda_url, user_id) ses.send_email( Source='sender@example.com', Destination={'ToAddresses': [email]}, Message={ 'Subject': {'Data': 'Approval Request'}, 'Body': { 'Text': { 'Data': f'Please approve the request by clicking on this link: {approval_url}' } } } ) return {'status': 'Emails sent'}
Approval Reception Lambda Function
import boto3 def lambda_handler(event, context): dynamodb = boto3.resource('dynamodb') table = dynamodb.Table('ApprovalsTable') user_id = event['queryStringParameters']['user_id'] response = event['queryStringParameters']['response'] table.update_item( Key={'UserId': user_id}, UpdateExpression='SET ApprovalStatus = :val1', ExpressionAttributeValues={':val1': response} ) return { 'statusCode': 200, 'body': 'Approval received' }
Check Approvals Lambda Function
import boto3 def lambda_handler(event, context): dynamodb = boto3.resource('dynamodb') table = dynamodb.Table('ApprovalsTable') response = table.scan( FilterExpression='ApprovalStatus = :val', ExpressionAttributeValues={':val': 'approve'} ) if response['Count'] == 2: return {'status': 'approved'} else: return {'status': 'not_approved'}
Snapshot Lambda Function
import boto3 def lambda_handler(event, context): ec2 = boto3.client('ec2') instance_id = 'i-1234567890abcdef0' snapshot = ec2.create_snapshot(InstanceId=instance_id, Description='Snapshot after approval') return {'status': 'Snapshot created', 'snapshot_id': snapshot['SnapshotId']}
ℹ️ Don't forget to handle permissions and environment variables appropriately. Each Lambda function will need the correct IAM permissions to interact with SES, DynamoDB, EC2, and other services as required.
The requester tagged the question with Step Functions and I don't see any workflows in the answer. Additionally, it is unclear how the approvals are collected from the approvers.