Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env node
const path = require('path');
const https = require('https');
const AWS = require('aws-sdk');
const promisePipe = require('promisepipe');
const unzip = require('unzipper');
const runner = async () => {
const runParams = {
taskDefinition: RUNNER,
launchType: "FARGATE",
networkConfiguration: {
awsvpcConfiguration: {
assignPublicIp: "ENABLED",
subnets: [SUBNET]
}
},
overrides: {
const runParams = {
taskDefinition: RUNNER,
launchType: "FARGATE",
networkConfiguration: {
awsvpcConfiguration: {
assignPublicIp: "ENABLED",
subnets: [SUBNET]
}
#!/usr/bin/env node
const path = require('path');
const https = require('https');
const AWS = require('aws-sdk');
const promisePipe = require('promisepipe');
const unzip = require('unzip');
const { argv } = require('yargs');
import AWS from 'aws-sdk';
export const handler = async (event, context, callback) => {
// Coming from environment variables setup in your `serverless.yaml` file
// See https://serverless.com/framework/docs/providers/aws/guide/variables/#referencing-environment-variables
const { RUNNER, SUBNET } = process.env;
const ecs = new AWS.ECS();
// Some other logic specific to your case here ...
FROM node:8
# Environment variables acting as parameters of the runner.
ENV AWS_LAMBDA_FUNCTION_EVENT {}
ENV AWS_LAMBDA_FUNCTION_CONTEXT {}
# Create app directory
WORKDIR /usr/src/app
COPY . .
iamRoleStatements:
...
# Allow running AWS Fargate containers when AWS Lambda timeout cannot be bypassed.
- Effect: 'Allow'
Action:
- ecs:RunTask
Resource: '*'
- Effect: Allow
Action:
- iam:PassRole
SQSFailureQueue:
Type: AWS::SQS::Queue
Properties:
QueueName: sqs-failure-queue
MessageRetentionPeriod: '1209600'
VisibilityTimeout: '60'
functions:
primaryHandler:
handler: path/to/immortal-handler.handler
name: immortal-handler
deadLetter:
targetArn:
GetResourceArn: SQSFailureQueue
secondaryHandler:
handler: path/to/immortal-handlerDlq.handler
name: immortal-handlerDql
environment:
REGION: eu-west-1
# ECS task to execute handler without timeout limitations
RUNNER: runner
# Required for runTask API call, preliminary created on AWS.
SUBNET: subnet-xxxxxxxx
...