AWS提供了很多替代cron的服务,例如:
import boto3
from botocore.exceptions import ClientError
def lambda_handler(event, context):
"""Scheduled Lambda function that takes an automatic snapshot of an RDS instance."""
rds = boto3.client('rds')
try:
response = rds.create_db_snapshot(
DBSnapshotIdentifier='snapshot-{}'.format(datetime.datetime.now().strftime('%Y-%m-%d-%H-%M')),
DBInstanceIdentifier='my-db-instance'
)
print("Snapshot created:", response)
except ClientError as e:
print("Snapshot not created:", e)
import boto3
batch = boto3.client('batch')
response = batch.submit_job(
jobName='my-batch-job',
jobQueue='my-job-queue',
jobDefinition='my-job-definition',
containerOverrides={
'environment': [
{
'name': 'VAR1',
'value': 'VALUE1'
},
{
'name': 'VAR2',
'value': 'VALUE2'
},
]
}
)
print("Job submitted:", response['jobId'])