@cfn-modules/fargate-scheduled-task

Fargate scheduled task

Usage no npm install needed!

<script type="module">
  import cfnModulesFargateScheduledTask from 'https://cdn.skypack.dev/@cfn-modules/fargate-scheduled-task';
</script>

README

cfn-modules: Fargate scheduled task

Executing an AWS Fargate task based on a schedule (comparable to a cronjob on Linux). Uses AWS Step Functions to control and monitor the task execution.

:books: Check out our new book Rapid Docker on AWS

  • Written for DevOps engineers and web developers who want to run dockerized web applications on AWS.
  • Prior knowledge of Docker and AWS is not required.
  • Continuous Deployment of your Web Application and Infrastructure as Code.

Install

Install Node.js and npm first!

npm i @cfn-modules/fargate-scheduled-task

Usage

---
AWSTemplateFormatVersion: '2010-09-09'
Description: 'cfn-modules example'
Resources:
  ScheduledTask:
    Type: 'AWS::CloudFormation::Stack'
    Properties:
      Parameters:
        ClusterModule: !GetAtt 'Cluster.Outputs.StackName' # required
        VpcModule: !GetAtt 'Vpc.Outputs.StackName' # required
        AlertingModule: '' # optional
        FileSystemModule1: '' # optional
        ClientSgModule1: '' # optional
        ClientSgModule2: '' # optional
        ClientSgModule3: '' # optional
        ManagedPolicyArns: '' # optional
        AppImage: '' # optional
        AppImageSecretModule '' # optional
        AppEntryPoint: '' # optional
        AppCommand: '' # optional
        AppEnvironment1Key: '' # optional
        AppEnvironment1Value: '' # optional
        AppEnvironment1SecretModule: '' # optional
        AppEnvironment2Key: '' # optional
        AppEnvironment2Value: '' # optional
        AppEnvironment2SecretModule: '' # optional
        AppEnvironment3Key: '' # optional
        AppEnvironment3Value: '' # optional
        AppEnvironment3SecretModule: '' # optional
        AppEnvironment4Key: '' # optional
        AppEnvironment4Value: '' # optional
        AppEnvironment5Key: '' # optional
        AppEnvironment5Value: '' # optional
        AppEnvironment6Key: '' # optional
        AppEnvironment6Value: '' # optional
        SidecarImage: '' # optional
        SidecarImageSecretModule '' # optional
        SidecarPort: '' # optional
        SidecarEnvironment1Key: '' # optional
        SidecarEnvironment1Value: '' # optional
        SidecarEnvironment1SecretModule: '' # optional
        SidecarEnvironment2Key: '' # optional
        SidecarEnvironment2Value: '' # optional
        SidecarEnvironment2SecretModule: '' # optional
        SidecarEnvironment3Key: '' # optional
        SidecarEnvironment3Value: '' # optional
        SidecarEnvironment3SecretModule: '' # optional
        Cpu: '' # optional
        Memory: '' # optional
        LogsRetentionInDays: '' # optional
        SubnetsReach: '' # optional
        ScheduleExpression: 'rate(15 minutes)' # optional
        Timeout: '' # optional
      TemplateURL: './node_modules/@cfn-modules/fargate-scheduled-task/module.yml'

Examples

none

Related modules

none

Parameters

Name Description Default Required? Allowed values
ClusterModule Stack name of ecs-cluster module yes
VpcModule Stack name of vpc module yes
AlertingModule Stack name of alerting module no
FileSystemModule1 Stack name of efs-file-system module mounted to /mnt/efs1 no
ClientSgModule1 Stack name of client-sg module to mark traffic from Fargate task no
ClientSgModule2 Stack name of client-sg module to mark traffic from Fargate task no
ClientSgModule3 Stack name of client-sg module to mark traffic from Fargate task no
ManagedPolicyArns Comma-delimited list of IAM managed policy ARNs to attach to the task's IAM role no
AppImage The Docker image to use for the app container. You can use images in the Docker Hub registry or specify other repositories (repository-url/image:tag). If the repository is private, set AppImageSecretModule as well! widdix/hello:v1 no
AppImageSecretModule Stack name of secret module which contains the repository credentials for private registry authentication no
AppEntryPoint Optional entry point for app container. no
AppCommand Optional command for app container. no
AppEnvironment1Key Environment variable 1 key for app container no
AppEnvironment1Value Environment variable 1 plain-text value for app container (if AppEnvironment1Key is set, set either AppEnvironment1Value or AppEnvironment1SecretModule) no
AppEnvironment1SecretModule Environment variable 1 stack name of secret module for app container (if AppEnvironment1Key is set, set either AppEnvironment1Value or AppEnvironment1SecretModule) no
AppEnvironment2Key Environment variable 2 key for app container no
AppEnvironment2Value Environment variable 2 plain-text value for app container (if AppEnvironment2Key is set, set either AppEnvironment2Value or AppEnvironment2SecretModule) no
AppEnvironment2SecretModule Environment variable 2 stack name of secret module for app container (if AppEnvironment2Key is set, set either AppEnvironment2Value or AppEnvironment2SecretModule) no
AppEnvironment3Key Environment variable 3 key for app container no
AppEnvironment3Value Environment variable 3 plain-text value for app container (if AppEnvironment3Key is set, set either AppEnvironment3Value or AppEnvironment3SecretModule) no
AppEnvironment3SecretModule Environment variable 3 stack name of secret module for app container (if AppEnvironment3Key is set, set either AppEnvironment3Value or AppEnvironment3SecretModule) no
AppEnvironment4Key Environment variable 4 key for app container no
AppEnvironment4Value Environment variable 4 plain-text value for app container no
AppEnvironment5Key Environment variable 5 key for app container no
AppEnvironment5Value Environment variable 5 plain-text value for app container no
AppEnvironment6Key Environment variable 6 key for app container no
AppEnvironment6Value Environment variable 6 plain-text value for app container no
SidecarImage Docker image to use for the sidecar container. You can use images in the Docker Hub registry or specify other repositories (repository-url/image:tag). If the repository is private, set SidecarImageSecretModule as well! no
SidecarImageSecretModule Stack name of secret module which contains the repository credentials for private registry authentication no
SidecarPort The port exposed by the sidecar container reachable from the app container on host localhost (SidecarPort != ProxyPort != AppPort) 9000 no
SidecarEnvironment1Key Environment variable 1 key for sidecar container no
SidecarEnvironment1Value Environment variable 1 plain-text value for sidecar container (if SidecarEnvironment1Key is set, set either SidecarEnvironment1Value or SidecarEnvironment1SecretModule) no
SidecarEnvironment1SecretModule Environment variable 1 stack name of secret module for sidecar container (if SidecarEnvironment1Key is set, set either SidecarEnvironment1Value or SidecarEnvironment1SecretModule) no
SidecarEnvironment2Key Environment variable 2 key for sidecar container no
SidecarEnvironment2Value Environment variable 2 plain-text value for sidecar container (if SidecarEnvironment2Key is set, set either SidecarEnvironment2Value or SidecarEnvironment2SecretModule) no
SidecarEnvironment2SecretModule Environment variable 2 stack name of secret module for sidecar container (if SidecarEnvironment2Key is set, set either SidecarEnvironment2Value or SidecarEnvironment2SecretModule) no
SidecarEnvironment3Key Environment variable 3 key for sidecar container no
SidecarEnvironment3Value Environment variable 3 plain-text value for sidecar container (if SidecarEnvironment3Key is set, set either SidecarEnvironment3Value or SidecarEnvironment3SecretModule) no
SidecarEnvironment3SecretModule Environment variable 3 stack name of secret module for sidecar container (if SidecarEnvironment3Key is set, set either SidecarEnvironment3Value or SidecarEnvironment3SecretModule) no
Cpu The minimum number of vCPUs to reserve for the container 0.25 no [0.25, 0.5, 1, 2, 4]
Memory The amount (in GB) of memory used by the task 0.5 no [0.5, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]
LogsRetentionInDays Specifies the number of days you want to retain log events in the specified log group 14 no [1, 3, 5, 7, 14, 30, 60, 90, 120, 150, 180, 365, 400, 545, 731, 1827, 3653]
SubnetsReach Should the service have direct access to the Internet or do you prefer private subnets with NAT? Public no [Public, Private]
ScheduleExpression The schedule or rate (frequency) that determines when CloudWatch Events runs the rule (for valid values, see http://docs.aws.amazon.com/AmazonCloudWatch/latest/events/ScheduledEvents.html) rate(1 hour) yes
Timeout The timeout for a task execution in seconds. 600 yes

Private repositories

To fetch Docker images from private repositories, you have to provide the repository credentials via AWS Secrets Manager. Go to AWS Secrets Manager and create a new secret of type other type) with the plaintext value:

{
  "username": "DOCKERHUB_USERNAME",
  "password": "DOCKERHUB_PASSWORD"
}

Use the secret module wrapper to use the secret within cfn-modules.

---
AWSTemplateFormatVersion: '2010-09-09'
Description: 'cfn-modules example'
Resources:
  Secret:
    Type: 'AWS::CloudFormation::Stack'
    Properties:
      Parameters:
        Arn: 'arn:aws:secretsmanager:eu-west-1:111111111111:secret:name/of/secret' # TODO replace with your secret ARN
      TemplateURL: './node_modules/@cfn-modules/secret/wrapper.yml'

The following image prameters support a secret:

Parameter Secret
 ProxyImage ProxyImageSecretModule
AppImage AppImageSecretModule
SidecarImage SidecarImageSecretModule