Skip to content

Commit

Permalink
Run the VIIRS climatology job the first 5 days of every month.
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkinsspatial committed Feb 7, 2024
1 parent 66e96a9 commit 48e7446
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 27 deletions.
34 changes: 34 additions & 0 deletions lambda_functions/laads_submit_climatology_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import datetime
import json
import os

import boto3

batch_client = boto3.client("batch")


jobQueue = os.getenv("JOB_QUEUE")
jobDefinition = os.getenv("JOB_DEFINITION")
lasrc_aux = os.getenv("LASRC_AUX_DIR")
laads_token = os.getenv("LAADS_TOKEN")
laads_bucket = os.getenv("LAADS_BUCKET")


def handler(event, context):
current_date = datetime.datetime.now()
response = batch_client.submit_job(
jobName="laads_cron",
jobQueue=jobQueue,
jobDefinition=jobDefinition,
containerOverrides={
"environment": [
{"name": "LASRC_AUX_DIR", "value": lasrc_aux},
{"name": "LAADS_TOKEN", "value": laads_token},
{"name": "LAADS_BUCKET", "value": laads_bucket},
{"name": "CLIM_YEAR", "value": current_date.year},
{"name": "CLIM_MONTH", "value": current_date.month},
],
"command": ["sh", "-c", "climatologies.sh"],
},
)
return response
50 changes: 23 additions & 27 deletions stack/hlsconstructs/batch_cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@


class BatchCron(Lambda):
"""AWS Batch Event Construct to Run Batch Jobs on a Cron using Lambda."""

def __init__(
self,
scope: core.Construct,
Expand All @@ -20,32 +18,30 @@ def __init__(
timeout: int = 10,
**kwargs,
) -> None:
if "code_file" not in kwargs:
jobdef = job.job.ref
env_str = aws_env(env)
code_str = f"""
import boto3
import json
batch_client = boto3.client('batch')
jobdef = job.job.ref

env_str = aws_env(env)

code_str = f"""
import boto3
import json
batch_client = boto3.client('batch')
def handler(event, context):
print(event)
print({env_str})
response = batch_client.submit_job(
jobName="{id}-job",
jobQueue="{queue}",
jobDefinition="{jobdef}",
containerOverrides={{
'environment': {env_str}
}}
)
print(response)
return response
"""
code_str = align(code_str)
self.code = aws_lambda.InlineCode(code=code_str)
def handler(event, context):
print(event)
print({env_str})
response = batch_client.submit_job(
jobName="{id}-job",
jobQueue="{queue}",
jobDefinition="{jobdef}",
containerOverrides={{
'environment': {env_str}
}}
)
print(response)
return response
"""
code_str = align(code_str)
self.code = aws_lambda.InlineCode(code=code_str)

super().__init__(scope, id, **kwargs)

Expand Down

0 comments on commit 48e7446

Please sign in to comment.