-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
149 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"""Sosw Essential Scheduler | ||
""" | ||
|
||
import logging | ||
|
||
from sosw.scheduler import Scheduler | ||
from sosw.app import LambdaGlobals, get_lambda_handler | ||
|
||
logger = logging.getLogger() | ||
logger.setLevel(logging.INFO) | ||
|
||
|
||
class Essential(Scheduler): | ||
pass | ||
|
||
|
||
global_vars = LambdaGlobals() | ||
lambda_handler = get_lambda_handler(Essential, global_vars) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sosw |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
AWSTemplateFormatVersion: "2010-09-09" | ||
Description: "sosw_scheduler" | ||
|
||
Parameters: | ||
ExecutionPolicy: | ||
Description: "Managed execution policy for sosw lambdas." | ||
Type: String | ||
Default: 'AWSLambdaBasicExecutionRole' | ||
|
||
ConfigTableName: | ||
Description: "Config Table." | ||
Type: String | ||
Default: 'config' | ||
|
||
Resources: | ||
|
||
LambdaSoswSchedulerRole: | ||
Type: "AWS::IAM::Role" | ||
Properties: | ||
AssumeRolePolicyDocument: | ||
Version: "2012-10-17" | ||
Statement: | ||
- Effect: Allow | ||
Principal: | ||
Service: | ||
- "lambda.amazonaws.com" | ||
Action: | ||
- "sts:AssumeRole" | ||
Path: "/" | ||
ManagedPolicyArns: | ||
- !Sub "arn:aws:iam::aws:policy/service-role/${ExecutionPolicy}" | ||
|
||
Policies: | ||
- PolicyName: "SoswSchedulerPermissions" | ||
PolicyDocument: | ||
Version: "2012-10-17" | ||
Statement: | ||
|
||
- Effect: "Allow" | ||
Action: "dynamodb:*" | ||
Resource: | ||
# - !Sub "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}/table/${Fn::ImportValue: 'sosw-ddb-tasks'}/*" | ||
- Fn::Join: | ||
- ':' | ||
- - !Sub "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}" | ||
- Fn::Join: | ||
- '/' | ||
- - "table" | ||
- Fn::ImportValue: "sosw-ddb-tasks" | ||
- "*" | ||
- Fn::Join: | ||
- ':' | ||
- - "arn:aws:dynamodb" | ||
- !Ref AWS::Region | ||
- !Ref AWS::AccountId | ||
- Fn::Join: | ||
- '/' | ||
- - "table" | ||
- Fn::ImportValue: "sosw-ddb-tasks" | ||
|
||
# You can provide access explicitly here, but we normally recommend keeping it in the Custom policy of ConfigTable. | ||
# See examples/yaml/sosw-shared-dynamodb.yaml | ||
- Effect: "Allow" | ||
Action: | ||
- "dynamodb:Query" | ||
- "dynamodb:DescribeTable" | ||
Resource: | ||
- !Sub "arn:aws:dynamodb:${AWS::Region}:${AWS::AccountId}:table/${ConfigTableName}" | ||
|
||
RoleName: "lambda_sosw_scheduler" | ||
|
||
|
||
################################# | ||
# Lambda Function for Essential # | ||
################################# | ||
LambdaSoswScheduler: | ||
Type: "AWS::Lambda::Function" | ||
Properties: | ||
Code: | ||
S3Bucket: !Sub "sosw-s3-${AWS::AccountId}" | ||
S3Key: "sosw/packages/sosw_scheduler.zip" | ||
Description: "ABS. CloudFormation managed sosw Scheduler." | ||
FunctionName: "sosw_scheduler" | ||
Handler: "app.lambda_handler" | ||
MemorySize: 1024 | ||
Role: !GetAtt LambdaSoswSchedulerRole.Arn | ||
Runtime: "python3.7" | ||
Timeout: 900 | ||
|
||
Tags: | ||
- | ||
Key: 'Environment' | ||
Value: 'dev' | ||
|
||
|
||
############################################## | ||
# Permissions for CloudWatch ScheduledEvents # | ||
# The actual Rules are configured in the # | ||
# scheduled-rules.yaml template. # | ||
############################################## | ||
PermissionForEventsToInvokeLambdaSoswScheduler: | ||
Type: "AWS::Lambda::Permission" | ||
Properties: | ||
FunctionName: | ||
Ref: "LambdaSoswScheduler" | ||
Action: "lambda:InvokeFunction" | ||
Principal: "events.amazonaws.com" | ||
|
||
|
||
############################################# | ||
# Export Values to CloudFormation Namespace # | ||
############################################# | ||
Outputs: | ||
|
||
LambdaSoswScheduler: | ||
Description: "Sosw Scheduler Essential" | ||
Value: !Ref LambdaSoswScheduler | ||
Export: | ||
Name: "sosw-lambda-scheduler" |