This repository has been archived by the owner on Sep 25, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from speee/spotfleet_cloudformation
SpotFleet CloudFormation
- Loading branch information
Showing
8 changed files
with
420 additions
and
0 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,7 @@ | ||
## How to Deploy | ||
|
||
```bash | ||
# BUCKET_NAME is used for `aws cloudformation package` | ||
# STACK_NAME is used for `aws cloudformation deploy` | ||
$ BUCKET_NAME=bucket-name STACK_NAME=stack-name bin/deploy | ||
``` |
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,30 @@ | ||
#!/bin/bash | ||
|
||
if [ -z "$BUCKET_NAME" ]; then | ||
echo 'BUCKET_NAME is required' | ||
exit 1 | ||
fi | ||
|
||
if [ -z "$STACK_NAME" ]; then | ||
echo 'STACK_NAME is required' | ||
exit 1 | ||
fi | ||
|
||
TEMPLATE_FILE=cloudformation.yml | ||
|
||
# Move project root | ||
cd "$(dirname "$(perl -e 'use Cwd "abs_path";print abs_path(shift)' "$0")")/.." || exit 1 | ||
|
||
sh -c 'cd ./functions/RunEcsTask && npm install && npm run build && cp -rf ./node_modules ./built/' | ||
|
||
mkdir -p ./built | ||
|
||
aws cloudformation package \ | ||
--template-file "$TEMPLATE_FILE" \ | ||
--output-template-file ./built/cloudformation.yml \ | ||
--s3-bucket "$BUCKET_NAME" | ||
|
||
aws cloudformation deploy \ | ||
--capabilities CAPABILITY_NAMED_IAM \ | ||
--template-file built/cloudformation.yml \ | ||
--stack-name "$STACK_NAME" |
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,23 @@ | ||
{ | ||
"name": "run-ecs-task", | ||
"version": "0.0.1", | ||
"description": "Lambda function that to run ECS Task", | ||
"main": "index.js", | ||
"scripts": { | ||
"build": "tsc -p ./tsconfig.json", | ||
"clean": "rm -rf ./built" | ||
}, | ||
"author": "", | ||
"license": "MIT", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/speee/webapp-revieee" | ||
}, | ||
"devDependencies": { | ||
"@types/aws-lambda": "0.0.12", | ||
"@types/node": "^7.0.31", | ||
"aws-sdk": "^2.71.0", | ||
"tslint": "^5.4.3", | ||
"typescript": "^2.3.4" | ||
} | ||
} |
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,32 @@ | ||
import { Callback, Context } from "aws-lambda"; | ||
import * as AWS from "aws-sdk"; | ||
|
||
const ecs = new AWS.ECS(); | ||
|
||
export function handler(event: any, context: Context, callback: Callback) { | ||
const envBranch: AWS.ECS.KeyValuePair = { | ||
name: "BRANCH", | ||
value: "master", | ||
}; | ||
const containerOverride: AWS.ECS.ContainerOverride = { | ||
name: "main", | ||
environment: [envBranch], | ||
}; | ||
const taskOverride: AWS.ECS.TaskOverride = { | ||
containerOverrides: [containerOverride], | ||
}; | ||
const params: AWS.ECS.RunTaskRequest = { | ||
cluster: "revieee", | ||
taskDefinition: "arn:aws:ecs:ap-northeast-1:951787653356:task-definition/im-ieul-core:3", | ||
overrides: taskOverride, | ||
}; | ||
|
||
(async () => { | ||
return await ecs.runTask(params).promise(); | ||
})().then((result: AWS.ECS.RunTaskResponse) => { | ||
console.log(result.tasks); | ||
callback(null, result.tasks[0].taskArn); | ||
}).catch((err: AWS.AWSError) => { | ||
callback(err); | ||
}); | ||
} |
Oops, something went wrong.