Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add typescript example of a Fargate service with efs mount #274

Merged
merged 134 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from 131 commits
Commits
Show all changes
134 commits
Select commit Hold shift + click to select a range
d55fa28
Fix broken links (#42)
Doug-AWS May 25, 2019
f858267
minor wording changes in readme files
orozcoadrian May 25, 2019
3c9cc68
minor wording changes
orozcoadrian May 25, 2019
59f7f9a
modernize python and typescript examples
May 30, 2019
561dfff
add default region in env
May 30, 2019
0f9bafb
feat: add example for AppSync GraphQL w/ DynamoDB CRUD resolvers (#44)
simalexan May 31, 2019
cde05b5
Updated Python examples to work with 0.33. Note that this still does…
garnaat Jun 2, 2019
e6a8c06
fix(elasticbeanstalk-bg-pipeline): Converted 'getContext' to 'tryGetC…
Jun 12, 2019
27e22e0
fix(elasticbeanstalk-environment): Converted 'getContext' to 'tryGetC…
Jun 12, 2019
015c310
fix(static-site): Converted 'getContext' to 'tryGetContext' (#49)
Jun 12, 2019
d3a34d5
fix(static-site): Converted 'AliasRecord' to new 'ARecord' and conver…
Jun 12, 2019
7afa37b
fix(typescript): Replaced all instances of 'app.run()' with 'app.synt…
Jun 13, 2019
b4951bd
Update ecs typescript examples to v0.36.1
piradeepk Jul 2, 2019
7a2ce64
Updating Python examples to 0.36.1 (#64)
garnaat Jul 3, 2019
3f8c30d
fix: many updates to fix for CDK 0.36.0 (#62)
tbadlov Jul 3, 2019
ca67569
feat: README - add table of contents (#51)
ScottBrenner Jul 3, 2019
28bf7b0
fix: ecs-service-with-logging - ECS, not Fargate (#52)
ScottBrenner Jul 3, 2019
51b05a6
chore(ecs-cluster): remove comment from the ecs cluster example (#67)
piradeepk Jul 5, 2019
1fcbbb9
fix: update Python StepFunctions project layout (#66)
rhboyd Jul 8, 2019
022e1f6
chore(overrides): add README to "overrides" example (#69)
rix0rrr Jul 8, 2019
729a88b
Updating all Python examples for CDK release 0.38 (#70)
garnaat Jul 8, 2019
82646a6
Update VPCProps to us maxAzs (#72)
piradeepk Jul 9, 2019
5ca4113
feat: README updates 0.39.0. Builds confirmed (#71)
NGL321 Jul 9, 2019
ca9819f
fix: rename flasks app.synth to app.run (#74)
pfeilbr Jul 12, 2019
2d23d5f
fix: remove duplicate grant in ddb example (#75)
jansepke Jul 12, 2019
d60cf57
fix: CDK General Availability (1.0.0) updates (#76)
skinny85 Jul 12, 2019
f0dc394
Delete README.txt
nathanpeck Jul 17, 2019
c1658cd
Fixes an invalid function name in the lambda-cron Java example, and u…
NutterzUK Jul 20, 2019
2f1587c
Removed * imports in favour of fully qualified single imports at the …
NutterzUK Jul 22, 2019
2c1d767
Remove functionName from java lambda-cron example.
NutterzUK Jul 23, 2019
5d765d5
Update java lambda-cron example expected CFT to have more realistic r…
NutterzUK Jul 23, 2019
91dc35e
Reverted changes to java lambda-cron example back to using SingletonF…
NutterzUK Jul 23, 2019
91fec8a
sets removal policy on S3 and DynamoDB to DESTROY
hellnation Aug 8, 2019
89dfbf4
chore: added issue/pr templates + mergify/semanticprs config (#101)
NGL321 Aug 13, 2019
e9da645
url-shortner from aws online tech talk
Aug 27, 2019
169797f
Updates
Aug 28, 2019
c2c9889
dummy values for external resources
Aug 28, 2019
64d505b
handle fake context in all builds
Aug 28, 2019
6fc6e20
dont fail synth
Aug 28, 2019
9e85039
chore: fix build for ElasticBeanStalk TypeScript examples
skinny85 Sep 5, 2019
216508b
feat: include DNS-validated ACM certificate and S3 bucket deployment …
clareliguori Sep 17, 2019
fd90aed
feat: example using S3 trigger for Lambda (#106)
pubudusj Sep 17, 2019
ba44512
feat: Python example for APIGW with lambda integration and CORS (#104)
norbinsh Sep 17, 2019
cf406d1
chore: update version of maven-compiler-plugin (#98)
sullis Sep 17, 2019
4953d33
feat: add Python example for Kinesis+Lambda (#77)
wulfmann Sep 17, 2019
3120693
fix: updated Policy Name to match new parameter format (#86)
rhboyd Sep 17, 2019
db7609c
Reference to Typescript >Python translation docs (#90)
stevenbryen Sep 17, 2019
ee509f4
feat: add C# port of TypeScript 'my-widget-service' (#92)
gweinhold Sep 17, 2019
28a2847
feat: make Python load balancer example start an actual HTTP server (…
stevensu1977 Sep 17, 2019
3c31afb
feat: (python) added my-widget-service example (#122)
rhboyd Sep 17, 2019
a5d5992
feat: Add python example for appsync-graphql-dynamodb (#121)
zanhsieh Sep 17, 2019
0c97b81
feat: add python/appsync-graphql-dynamodb/README.md (#124)
zanhsieh Sep 18, 2019
cdd0a93
fix: Update Fargate LoadBalance Service examples (#126)
garnaat Sep 18, 2019
3c28d18
fix: update static site example after breaking changes
clareliguori Sep 20, 2019
5c17f20
fix: update fargate-service-with-auto-scaling (#139)
netroy Oct 14, 2019
89483b1
fix: update ecs-patterns examples to use the latest version of the cd…
piradeepk Oct 14, 2019
48d18b6
feat: added a CodePipeline Python example building a Docker image (#140)
josjaf Oct 21, 2019
e52cb74
feat(ecs/elbv2): add example showing how to share LB across stacks
Oct 24, 2019
71a88e9
chore: update lambda.Runtime to NODEJS_10_X (#133)
trivikr Oct 25, 2019
c202de4
The Python version specified in the Lambda runtime has been changed f…
curry9999 Oct 27, 2019
5c24138
fix: correct minor typos in code (#150)
mounick-mallow Nov 1, 2019
6945db7
chore: update Java examples (#144)
RomainMuller Nov 1, 2019
0d7c9dc
chore: clean up C# example (#143)
RomainMuller Nov 1, 2019
6e6c665
Change to loadBalancerTarget() (#142)
iamhopaul123 Nov 1, 2019
56a493a
feat: add RandomWriter C# example (#153)
RomainMuller Nov 8, 2019
6e58acb
custom resource example for Java
Nov 22, 2019
31d76b9
fix: update the Python URL shortener example with the new cdk.context…
skinny85 Nov 22, 2019
bae8d11
implemented Builder.create() pattern for the resources
Nov 22, 2019
bcd6a5a
chore: refresh Java examples with latest syntax elements (#162)
RomainMuller Nov 23, 2019
0091e31
Fix typos in appsync-graphql-dynamodb/requirements.txt (#157)
wingkwong Nov 25, 2019
9f13a46
adding java examples for static site and stepfunctions-job-poller
Nov 26, 2019
12de74a
feat: add RDS sample in Python (#158)
wingkwong Nov 26, 2019
779426d
fix: Allow ingress traffic from public internet for NLB Ec2/Fargate S…
iamhopaul123 Nov 27, 2019
49b4722
Added .NET link to README. (#193)
curry9999 Dec 3, 2019
2c60fdb
feat: Add C# Static-Site (#173)
rhboyd Dec 3, 2019
f7d5cdd
Example Formatting
MrArnoldPalmer Dec 3, 2019
250b76b
feat: Add C# StepFunctions Job Poller (#174)
rhboyd Dec 3, 2019
15f218a
feat(Java): add Java code for resource-overrides example. (#167)
pimlock Dec 4, 2019
81654b7
feat: my-widget-service example for Java (#172)
srihariph Dec 4, 2019
10947b7
feat: Add C# Classic Load Balancer (#180)
rhboyd Dec 4, 2019
146e2ea
added the static site and stepfunctions java examples info to ReadMe
Dec 4, 2019
d827505
feat: Format Java Code (#199)
MrArnoldPalmer Dec 4, 2019
4478f8d
update cdk version numbers (#171)
zechariahks Dec 7, 2019
e9337f2
Upgrade typescript version to resolve implicitly issue (#159)
wingkwong Dec 7, 2019
07437b5
fix(java/resource-overrides): example uses method toPrettyString() wh…
skinny85 Dec 11, 2019
aeeb38f
feat: c# project with a c# lambda function handler (#202)
nija-at Dec 12, 2019
817403b
feat: added ECS fargate-load-balanced-service Java example (#160)
vinayselvaraj Dec 13, 2019
5da35a9
Updated SG to include VPC Cide (#191)
dchristian3188 Dec 13, 2019
b8a7ab1
updated Python Fargate Service load balance example for security grou…
dchristian3188 Dec 13, 2019
bc8f659
updated ts version (#207)
NGL321 Dec 20, 2019
e5cab1d
feat(new-ex): add an Amplify Console App Example (#59)
simalexan Dec 21, 2019
a2df833
feat: Add C# ElasticBeanstalk (#182)
rhboyd Dec 21, 2019
da606d4
fix: update travis to use jsii superchain (#219)
NGL321 Jan 3, 2020
2a61ae9
feat(new-ex): add AppSync triggering Event Bridge Example (#103)
awsed Jan 3, 2020
80056df
Add requirements.txt for python/api-cors-lambda (#200)
no-brand Jan 4, 2020
62269ae
Update README.md (#213)
curry9999 Jan 4, 2020
cc3643d
fix: update CDK versions for Java examples to latest (#217)
NGL321 Jan 4, 2020
8967297
feat(new-ex): custom logical names (#120)
Jan 8, 2020
e91f90a
fix: broken build (#225)
nija-at Jan 10, 2020
fda7e12
feat(repo): add dotnet buildscripts (#229)
NGL321 Jan 16, 2020
ed60299
chore(csharp): update cdk configs for new csharp CI builds
NGL321 Jan 16, 2020
d446e40
feat(repo): add actions CI to repo (#231)
NGL321 Jan 16, 2020
ac97747
feat(py-stepfunctions): add step-mapping to example (#215)
sarveshbhagat Jan 16, 2020
1c290f3
feat: add 3 tier app, usage of userdata, sec grps (#214)
esn89 Jan 16, 2020
a69a07f
feat: Passing resources between stacks (#210)
richardhboyd Jan 16, 2020
3366b23
feat: add VPC, EC2 Python Example (#204)
huangzbaws Jan 21, 2020
91ff64a
feat: Add EKS cluster with VPC and self managed ASG example (#224)
andskli Jan 21, 2020
f5783e4
feat: DynamoDB, Lambda and CloudWatch Example (#220)
sarveshbhagat Jan 22, 2020
2a33113
chore: remove Travis CI config file (#233)
NGL321 Jan 29, 2020
aeb8125
feat: Add codebuild cdk examples to create Project, ReportGroup… (#235)
jigar-lab Jan 30, 2020
9150f32
feat: Java :implementation of classic load balancer sample (#187)
djiten75 Feb 5, 2020
da6906a
fix: change ecs local example to ALB (#242)
iamhopaul123 Feb 7, 2020
bde276f
fix: Fixes broken link for ecs-network-load-balanced-service exa… (#243)
chrisnankervis Feb 17, 2020
4a6e1a4
feat: Java api cors lambda crud dynamodb (#196)
djiten75 Feb 19, 2020
b92b9f6
chore: update version of checkout action in workflow (#247)
ScottBrenner Feb 28, 2020
7d73bd5
feat(newex): example of Cognito-protected APIGateway backed by L… (#252)
campionfellin Mar 3, 2020
bfc9ece
fix: broken build (#255)
nija-at Mar 6, 2020
c3b6669
feat: add lambda-ddb-mysql-etl-pipeline python service (#134)
benfarr Mar 17, 2020
077e0c1
feat:add a multi rule ALB sample with host and path based routing (#257)
nataibi Mar 17, 2020
a8ca87c
fix: Typo in README (#258)
melzareix Mar 17, 2020
837ad24
fix: csharp example RandomWriter does not build
shivlaks Mar 25, 2020
082c091
Revert "fix: csharp example RandomWriter does not build"
shivlaks Mar 25, 2020
caeffe8
fix: csharp example RandomWriter does not work
shivlaks Mar 25, 2020
1160db7
chore: unpin cdk versions so they can serve as canaries for changes t…
shivlaks Mar 25, 2020
900a895
chore: remove pinned dependencies for csharp examples
shivlaks Mar 28, 2020
6ef9077
fix: indicate port 80 is http NOT ssh (#273)
ColWillis Apr 14, 2020
8fb4c64
Merge pull request #1 from aws-samples/master
maskerade Apr 16, 2020
6f0b887
Add example of fargate service with an efs filesystem mount
maskerade Apr 16, 2020
a0f3297
Merge branch 'master' into fargate-service-with-efs
NGL321 May 28, 2020
aa3cedc
Update with requested changes & add readme - also bump cdk packages t…
maskerade Jun 23, 2020
a9881c5
Fix aws-cdk package versions
maskerade Jun 23, 2020
c967d03
Merge branch 'master' into fargate-service-with-efs
NGL321 Jun 23, 2020
b613169
Merge branch 'master' into fargate-service-with-efs
maskerade Jun 26, 2020
a67cb1c
Merge branch 'master' into fargate-service-with-efs
maskerade Jun 26, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ $ cdk destroy
| [ecs-service-with-logging](https://github.com/aws-samples/aws-cdk-examples/tree/master/typescript/ecs/ecs-service-with-logging/) | Starting a container fronted by a load balancer on ECS |
| [fargate-service-with-logging](https://github.com/aws-samples/aws-cdk-examples/tree/master/typescript/ecs/fargate-service-with-logging/) | Starting a container fronted by a load balancer on Fargate |
| [custom-logical-names](https://github.com/aws-samples/aws-cdk-examples/tree/master/typescript/custom-logical-names/) | Example of how to override logical name allocation |
| [fargate-service-with-efs](https://github.com/aws-samples/aws-cdk-examples/tree/master/typescript/ecs/fargate-service-with-efs/) | Starting a container fronted by an application load balancer on Fargate with an EFS Mount |

## Java examples <a name="Java"></a>

Expand Down
34 changes: 34 additions & 0 deletions typescript/ecs/fargate-service-with-efs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Fargate Service using EFS
This example creates a Public Facing load balanced Fargate service with an EFS Filesystem mount to demo the
recently added feature to Fargate.

Is based on this blog post: https://aws.amazon.com/blogs/aws/amazon-ecs-supports-efs/

Also gives examples of using the following:

* AWS SDK Api call Custom resource to create Efs Access Point (not currently supported by cfn)
* Lambda Custom Resource to create ECS TaskDefinition with EFS Mount (not currently supported by cfn) & initiate an update of the service
* Cfn property override to set Fargate Service' PlatformVersion' to '1.4.0' (not currently tagged as Latest)


## Build

To build this app, you need to be in this example's root folder. Then run the following:

```bash
npm install -g aws-cdk
npm install
npm run build
```

This will install the necessary CDK, then this example's dependencies, and then build your TypeScript files and your CloudFormation template.

## Deploy

Run `cdk deploy`. This will deploy / redeploy your Stack to your AWS Account.

After the deployment you will see the API's URL, which represents the url you can then use.

## Synthesize Cloudformation Template

To see the Cloudformation template generated by the CDK, run `cdk synth`, then check the output file in the "cdk.out" directory.
3 changes: 3 additions & 0 deletions typescript/ecs/fargate-service-with-efs/cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"app": "node index"
}
51 changes: 51 additions & 0 deletions typescript/ecs/fargate-service-with-efs/efs-mount-fargate-cr.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import * as lambda from '@aws-cdk/aws-lambda';
import * as cdk from '@aws-cdk/core';
import * as iam from '@aws-cdk/aws-iam';
import * as cr from '@aws-cdk/custom-resources';
import fs = require('fs');


export interface FargateEfsCustomResourceProps {
/**
* Custom Resource Properties
*/
TaskDefinition: string;
EcsService: string;
EcsCluster: string;
EfsFileSystemId: string;
EfsMountName: string
}


export class FargateEfsCustomResource extends cdk.Construct {
public readonly response: string;

constructor(scope: cdk.Construct, id: string, props: FargateEfsCustomResourceProps) {
super(scope, id);

const onEvent = new lambda.SingletonFunction(this, 'Singleton', {
uuid: 'f7d4f730-4ee1-11e8-9c2d-fa7ae01bbebc',
code: new lambda.InlineCode(fs.readFileSync('lambda.js', { encoding: 'utf-8' })),
handler: 'index.handler',
timeout: cdk.Duration.seconds(300),
runtime: lambda.Runtime.NODEJS_12_X,
initialPolicy:[
new iam.PolicyStatement({
actions: [ 'ecs:UpdateService', 'ecs:RegisterTaskDefinition', 'ecs:DescribeTaskDefinition', 'iam:PassRole', 'iam:GetRole' ],
resources: [ '*' ]
})
]
});

const myProvider = new cr.Provider(this, 'MyProvider', {
onEventHandler: onEvent
});

const resource = new cdk.CustomResource(this, 'Resource1', {
serviceToken: myProvider.serviceToken,
properties: props
});

this.response = resource.getAtt('Response').toString();
}
}
105 changes: 105 additions & 0 deletions typescript/ecs/fargate-service-with-efs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import * as cdk from '@aws-cdk/core';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as ecs from '@aws-cdk/aws-ecs';
import * as ecs_patterns from '@aws-cdk/aws-ecs-patterns';
import * as efs from '@aws-cdk/aws-efs';
import * as cr from '@aws-cdk/custom-resources';
import {FargateEfsCustomResource} from "./efs-mount-fargate-cr";



class FargateEfs extends cdk.Stack {
constructor(scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props);

const vpc = new ec2.Vpc(this, 'DefaultVpc', { maxAzs: 2});
const ecsCluster = new ecs.Cluster(this, 'DefaultEcsCluster', {vpc: vpc});

const fileSystem = new efs.FileSystem(this, 'MyEfsFileSystem', {
vpc: vpc,
encrypted: true,
lifecyclePolicy: efs.LifecyclePolicy.AFTER_14_DAYS,
performanceMode: efs.PerformanceMode.GENERAL_PURPOSE,
throughputMode: efs.ThroughputMode.BURSTING
});


const params = {
FileSystemId: fileSystem.fileSystemId,
PosixUser: {
Gid: 1000,
Uid: 1000
},
RootDirectory: {
CreationInfo: {
OwnerGid: 1000,
OwnerUid: 1000,
Permissions: '755'
},
Path: '/uploads'
},
Tags: [
{
Key: 'Name',
Value: 'ecsuploads'
}
]
};

const efsAccessPoint = new cr.AwsCustomResource(this, 'EfsAccessPoint', {
onUpdate: {
service: 'EFS',
action: 'createAccessPoint',
parameters: params,
physicalResourceId: cr.PhysicalResourceId.of('12121212121'),
},
policy: cr.AwsCustomResourcePolicy.fromSdkCalls({resources: cr.AwsCustomResourcePolicy.ANY_RESOURCE})
});

efsAccessPoint.node.addDependency(fileSystem);

const taskDef = new ecs.FargateTaskDefinition(this, "MyTaskDefinition", {
memoryLimitMiB: 512,
cpu: 256,
});

const containerDef = new ecs.ContainerDefinition(this, "MyContainerDefinition", {
image: ecs.ContainerImage.fromRegistry("coderaiser/cloudcmd"),
taskDefinition: taskDef
});

containerDef.addPortMappings({
containerPort: 8000
});

const albFargateService = new ecs_patterns.ApplicationLoadBalancedFargateService(this, 'Service01', {
cluster: ecsCluster,
taskDefinition: taskDef,
desiredCount: 2
});

albFargateService.targetGroup.setAttribute('deregistration_delay.timeout_seconds', '30');

// Override Platform version (until Latest = 1.4.0)
const albFargateServiceResource = albFargateService.service.node.findChild('Service') as ecs.CfnService;
albFargateServiceResource.addPropertyOverride('PlatformVersion', '1.4.0')

// Allow access to EFS from Fargate ECS
fileSystem.connections.allowDefaultPortFrom(albFargateService.service.connections);

//Custom Resource to add EFS Mount to Task Definition
const resource = new FargateEfsCustomResource(this, 'FargateEfsCustomResource', {
TaskDefinition: taskDef.taskDefinitionArn,
EcsService: albFargateService.service.serviceName,
EcsCluster: ecsCluster.clusterName,
EfsFileSystemId: fileSystem.fileSystemId,
EfsMountName: 'uploads'
});

resource.node.addDependency(albFargateService);
}
}

const app = new cdk.App();
new FargateEfs(app, 'FargateEfsDemo01');
app.synth();
120 changes: 120 additions & 0 deletions typescript/ecs/fargate-service-with-efs/lambda.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
var AWS = require('aws-sdk');
var ecs = new AWS.ECS();

exports.handler = function(event, context, callback) {

var taskDefParams = {
taskDefinition: event["ResourceProperties"]["TaskDefinition"],
};

var ecsParams = {
service: event["ResourceProperties"]["EcsService"],
cluster: event["ResourceProperties"]["EcsCluster"]
};

var volume = {
name: event["ResourceProperties"]["EfsMountName"],
efsVolumeConfiguration: { fileSystemId: event["ResourceProperties"]["EfsFileSystemId"], rootDirectory: '/' }
};

var mountPoint = {
sourceVolume: event["ResourceProperties"]["EfsMountName"],
containerPath: '/' + event["ResourceProperties"]["EfsMountName"],
readOnly: false
};

console.log(event);
console.log(event["ResourceProperties"]);
try {
console.log("Getting Task Definition");
ecs.describeTaskDefinition(taskDefParams, function(err, data) {
if (err)
console.log(err, err.stack);
else
data['taskDefinition']['volumes'].push(volume);
data['taskDefinition']['containerDefinitions'][0]['mountPoints'].push(mountPoint);
delete data['taskDefinition']['taskDefinitionArn'];
delete data['taskDefinition']['revision'];
delete data['taskDefinition']['status'];
delete data['taskDefinition']['requiresAttributes'];
delete data['taskDefinition']['compatibilities'];

console.log("Register New Task Definition");
ecs.registerTaskDefinition(data['taskDefinition'], function(err, data) {
if (err)
console.log(err, err.stack);
else
console.log(data);
console.log("Update Service");
ecs.updateService({
service: ecsParams['service'],
cluster: ecsParams['cluster'],
taskDefinition: data['taskDefinition']['taskDefinitionArn'],

},
function (err, data) {
if (err)
console.log(err, err.stack);
else
console.log(data);
sendResponse(event, context, 'SUCCESS', { 'Message': 'Resource creation successful!' });
});
console.log(data);
});
});
} catch (e) {
console.log('Errors' + e);
sendResponse(event, context, 'FAILED')
}
};


// Send response to the pre-signed S3 URL
function sendResponse (event, context, responseStatus, responseData) {
console.log('Sending response ' + responseStatus);
var responseBody = JSON.stringify({
Status: responseStatus,
Reason: 'See the details in CloudWatch Log Stream: ' + context.logStreamName,
PhysicalResourceId: context.logStreamName,
StackId: event.StackId,
RequestId: event.RequestId,
LogicalResourceId: event.LogicalResourceId,
Data: responseData
});

console.log('RESPONSE BODY:\n', responseBody);

var https = require('https');
var url = require('url');

var parsedUrl = url.parse(event.ResponseURL);
var options = {
hostname: parsedUrl.hostname,
port: 443,
path: parsedUrl.path,
method: 'PUT',
headers: {
'content-type': '',
'content-length': responseBody.length
}
};

console.log('SENDING RESPONSE...\n');

var request = https.request(options, function (response) {
console.log('STATUS: ' + response.statusCode);
console.log('HEADERS: ' + JSON.stringify(response.headers));
// Tell AWS Lambda that the function execution is done
context.done()
});

request.on('error', function (error) {
console.log('sendResponse Error:' + error);
// Tell AWS Lambda that the function execution is done
context.done()
});

// write data to request body
request.write(responseBody);
request.end()
}
29 changes: 29 additions & 0 deletions typescript/ecs/fargate-service-with-efs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "fargate-service-with-efs",
"version": "1.0.0",
"description": "Running a load balanced service on ECS with EFS",
"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.9.5"
},
"dependencies": {
"@aws-cdk/aws-ec2": "*",
"@aws-cdk/aws-ecs": "*",
"@aws-cdk/aws-ecs-patterns": "*",
"@aws-cdk/aws-efs": "*",
"@aws-cdk/core": "*",
"@aws-cdk/custom-resources": "*"
}
}
21 changes: 21 additions & 0 deletions typescript/ecs/fargate-service-with-efs/tsconfig.json
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
}
}