ancient-waitress-68473
07/10/2024, 9:36 AMimport * as pulumi from '@pulumi/pulumi';
import * as aws from '@pulumi/aws';
import * as awsx from '@pulumi/awsx';
const config = new pulumi.Config();
// Create a security group that allows inbound access on Redis default port
const securityGroup = new aws.ec2.SecurityGroup('redisSecurityGroup', {
ingress: [
{
protocol: 'tcp',
fromPort: 6379,
toPort: 6379,
cidrBlocks: ['0.0.0.0/0'],
},
],
});
// Create an ElastiCache Redis Cluster
const redisCluster = new aws.elasticache.Cluster('redisCluster', {
engine: 'redis',
nodeType: 'cache.t2.micro',
numCacheNodes: 1,
parameterGroupName: 'default.redis7',
securityGroupIds: [securityGroup.id],
});
// An ECS cluster to deploy into.
const cluster = new aws.ecs.Cluster('cluster', {});
// Create a load balancer to listen for requests and route them to the container.
const loadbalancer = new awsx.lb.ApplicationLoadBalancer('loadbalancer', {});
// Create the ECR repository to store our container image
const repo = new awsx.ecr.Repository('repo', {
forceDelete: true,
});
// Build and publish our application's container image from ./app to the ECR repository.
const image = new awsx.ecr.Image('dr-server-image', {
repositoryUrl: repo.url,
platform: 'linux/amd64',
args: {
path: './',
},
});
// Define the service and configure it to use our image and load balancer.
new awsx.ecs.FargateService('dr-service', {
cluster: cluster.arn,
desiredCount: 1,
assignPublicIp: true,
taskDefinitionArgs: {
container: {
name: 'awsx-ecs',
image: image.imageUri,
cpu: 4096,
memory: 8192,
essential: true,
portMappings: [
{
containerPort: 80,
targetGroup: loadbalancer.defaultTargetGroup,
},
],
environment: [
{
name: 'REDIS_URL',
value: pulumi.interpolate`redis://${redisCluster.cacheNodes[0].address}:6379?family=6`,
},
],
healthCheck: {
command: ['CMD-SHELL', 'curl -f <http://127.0.0.1/health> || exit 1'],
interval: 300,
timeout: 30,
retries: 3,
},
},
},
});
// Export the URL so we can easily access it.
export const frontendURL = pulumi.interpolate`http://${loadbalancer.loadBalancer.dnsName}`;
quick-house-41860
07/11/2024, 3:43 PM