Skip to content

Instantly share code, notes, and snippets.

@kalinchernev
Last active September 3, 2018 11:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kalinchernev/7c164d079fa2114cd23e160c2cc95681 to your computer and use it in GitHub Desktop.
Save kalinchernev/7c164d079fa2114cd23e160c2cc95681 to your computer and use it in GitHub Desktop.
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