forked from aws-samples/aws-glue-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: fargate service using a local image (aws-samples#33)
- Loading branch information
Showing
7 changed files
with
111 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"app": "node index" | ||
} |
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,25 @@ | ||
import ec2 = require('@aws-cdk/aws-ec2'); | ||
import ecs = require('@aws-cdk/aws-ecs'); | ||
import cdk = require('@aws-cdk/cdk'); | ||
import path = require('path'); | ||
|
||
const app = new cdk.App(); | ||
const stack = new cdk.Stack(app, 'FargateServiceWithLocalImage'); | ||
|
||
// Create VPC and Fargate Cluster | ||
// NOTE: Limit AZs to avoid reaching resource quotas | ||
const vpc = new ec2.VpcNetwork(stack, 'MyVpc', { maxAZs: 2 }); | ||
const cluster = new ecs.Cluster(stack, 'Cluster', { vpc }); | ||
|
||
// Instantiate Fargate Service with a cluster and a local image that gets | ||
// uploaded to an S3 staging bucket prior to being uploaded to ECR. | ||
// A new repository is created in ECR and the Fargate service is created | ||
// with the image from ECR. | ||
new ecs.LoadBalancedFargateService(stack, "FargateService", { | ||
cluster, | ||
image: ecs.ContainerImage.fromAsset(stack, "local-image" , { | ||
directory: path.join(__dirname, 'local-image') | ||
}) | ||
}); | ||
|
||
app.run(); |
20 changes: 20 additions & 0 deletions
20
typescript/ecs/fargate-service-with-local-image/local-image/Dockerfile
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,20 @@ | ||
# Use an official Python runtime as a parent image | ||
FROM python:3.4-alpine | ||
|
||
# Set the working directory to /app | ||
WORKDIR /app | ||
|
||
# Copy the current directory contents into the container at /app | ||
COPY . /app | ||
|
||
# Install any needed packages specified in requirements.txt | ||
RUN pip install --trusted-host pypi.python.org -r requirements.txt | ||
|
||
# Make port 80 available to the world outside this container | ||
EXPOSE 80 | ||
|
||
# Define environment variable | ||
ENV NAME World | ||
|
||
# Run app.py when the container launches | ||
CMD ["python", "app.py"] |
15 changes: 15 additions & 0 deletions
15
typescript/ecs/fargate-service-with-local-image/local-image/app.py
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,15 @@ | ||
from flask import Flask | ||
import os | ||
import socket | ||
|
||
app = Flask(__name__) | ||
|
||
@app.route("/") | ||
def hello(): | ||
html = "<h3>Hello {name}!</h3>" \ | ||
"<b>Hostname:</b> {hostname}<br/>" | ||
return html.format(name=os.getenv("NAME", "world"), hostname=socket.gethostname()) | ||
|
||
if __name__ == "__main__": | ||
app.run(host='0.0.0.0', port=80) | ||
|
1 change: 1 addition & 0 deletions
1
typescript/ecs/fargate-service-with-local-image/local-image/requirements.txt
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 @@ | ||
flask |
26 changes: 26 additions & 0 deletions
26
typescript/ecs/fargate-service-with-local-image/package.json
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,26 @@ | ||
{ | ||
"name": "fargate-service-with-local-image", | ||
"version": "0.25.1", | ||
"description": "Running a load balanced service on Fargate with an image loaded locally", | ||
"private": true, | ||
"scripts": { | ||
"build": "tsc", | ||
"watch": "tsc -w", | ||
"cdk": "cdk" | ||
}, | ||
"author": { | ||
"name": "Amazon Web Services", | ||
"url": "https://aws.amazon.com", | ||
"organization": true | ||
}, | ||
"license": "Apache-2.0", | ||
"devDependencies": { | ||
"@types/node": "^8.10.38", | ||
"typescript": "^3.2.4" | ||
}, | ||
"dependencies": { | ||
"@aws-cdk/aws-ec2": "*", | ||
"@aws-cdk/aws-ecs": "*", | ||
"@aws-cdk/cdk": "*" | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
typescript/ecs/fargate-service-with-local-image/tsconfig.json
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,21 @@ | ||
{ | ||
"compilerOptions": { | ||
"target":"ES2018", | ||
"module": "commonjs", | ||
"lib": ["es2016", "es2017.object", "es2017.string"], | ||
"strict": true, | ||
"noImplicitAny": true, | ||
"strictNullChecks": true, | ||
"noImplicitThis": true, | ||
"alwaysStrict": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noImplicitReturns": true, | ||
"noFallthroughCasesInSwitch": false, | ||
"inlineSourceMap": true, | ||
"inlineSources": true, | ||
"experimentalDecorators": true, | ||
"strictPropertyInitialization":false | ||
} | ||
} | ||
|