Last active
September 3, 2018 11:33
-
-
Save kalinchernev/7c164d079fa2114cd23e160c2cc95681 to your computer and use it in GitHub Desktop.
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
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 ... | |
try { | |
const runParams = { | |
taskDefinition: RUNNER, | |
launchType: 'FARGATE', | |
networkConfiguration: { | |
awsvpcConfiguration: { | |
assignPublicIp: 'ENABLED', | |
subnets: [SUBNET], | |
}, | |
}, | |
overrides: { | |
containerOverrides: [ | |
{ | |
environment: [ | |
{ | |
name: 'AWS_LAMBDA_FUNCTION_EVENT', | |
value: JSON.stringify(event), | |
}, | |
// Help the runner locate the handler to run inside a container. | |
{ | |
name: 'AWS_LAMBDA_HANDLER_PATH', | |
// Matches path/to/immortal-handler.handler | |
value: 'path/to/immortal-handler.js', | |
}, | |
{ | |
name: 'AWS_LAMBDA_FUNCTION_CONTEXT', | |
value: JSON.stringify(context), | |
}, | |
... | |
], | |
name: RUNNER, | |
}, | |
], | |
}, | |
}; | |
const result = await ecs.runTask(runParams).promise(); | |
// Returns null | |
return callback(null, result); | |
} catch (e) { | |
return callback(e); | |
} | |
}; | |
export default handler; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment