sparse-intern-71089
06/27/2023, 6:33 PMsalmon-account-74572
06/27/2023, 6:49 PMcareful-vegetable-11632
06/27/2023, 6:51 PMcareful-vegetable-11632
06/27/2023, 6:51 PMcareful-vegetable-11632
06/27/2023, 8:26 PMsalmon-account-74572
06/27/2023, 8:37 PMpulumi up
the code it gave you and got an error, you can tell Pulumi AI to fix the error and supply the error details. It is often able to correct mistakes in the initial code it provided. Might be worth a try. At the very least, it should have provided enough information on creating an RDS instance, as well as a link to the docs, to get you rolling.billowy-army-68599
careful-vegetable-11632
06/27/2023, 8:51 PMcareful-vegetable-11632
06/27/2023, 8:51 PMcareful-vegetable-11632
06/27/2023, 8:52 PMimport pulumi
import pulumi_aws as aws
import pulumi_awsx as awsx
import os
# Load the environment variables
PYPI_INDEX_URL = os.environ.get("PYPI_INDEX_URL")
# TODO: Get PYPI_INDEX_URL using Pulumi instead
# TODO: I have run export DOCKER_SCAN_SUGGEST=false to get rid of the warning. Need to fix vulnerabilities
# Get default VPC
vpc = aws.ec2.DefaultVpc('default')
# Create a SecurityGroup that allows HTTP ingress and unrestricted egress
web_sg = aws.ec2.SecurityGroup(
'web-secgrp',
vpc_id=vpc.id,
ingress=[{
'protocol': 'tcp',
'from_port': 80,
'to_port': 80,
'cidr_blocks': ['0.0.0.0/0'],
}]
)
# Create an RDS SecurityGroup that allows PostgreSQL egress from the Web SecurityGroup
rds_sg = aws.ec2.SecurityGroup(
'rds-secgrp',
egress=[aws.ec2.SecurityGroupEgressArgs(protocol='-1', from_port=0, to_port=0, cidr_blocks=['0.0.0.0/0'])],
ingress=[aws.ec2.SecurityGroupIngressArgs(
protocol='tcp', from_port=5432, to_port=5432, security_groups=[web_sg]),
]
)
# Create an AWS RDS PostgreSQL database
database = aws.rds.Instance(
"turnstaydb",
engine="postgres",
engine_version = '14.7',
instance_class="db.t3.micro",
allocated_storage=20,
name="turnstaybd",
username="postgres",
password="G1v*y3#i13P9",
publicly_accessible=True,
skip_final_snapshot=True,
vpc_security_group_ids=[rds_sg.id]
)
# An ECS Fargate cluster
cluster = aws.ecs.Cluster("TurnStayCluster")
# Creating a ECR Repository
repository = awsx.ecr.Repository("TunStayAPIRepository")
#Creating a ECR Image
image = awsx.ecr.Image("tunstay-api-image",
repository_url=repository.url,
args ={"PYPI_INDEX_URL": PYPI_INDEX_URL},
path="../"
)
# Create the AWS Load Balancer
lb = awsx.lb.ApplicationLoadBalancer(
"TurnStayLoadBalancer",
)
# Task definition for the Fargate service
task_def = awsx.ecs.FargateTaskDefinition(
"TurnStayApiTaskDef",
containers={
"TurnStayApi": awsx.ecs.TaskDefinitionContainerDefinitionArgs(
image=image.image_uri,
memory=128,
cpu=512,
essential=True,
port_mappings=[awsx.ecs.TaskDefinitionPortMappingArgs(target_group=lb.default_target_group,)],
environment =[
{
"name": database.endpoint,
"value": "<http://turnstay-staging-database-1.cwxi1s8c9ygu.eu-west-1.rds.amazonaws.com|turnstay-staging-database-1.cwxi1s8c9ygu.eu-west-1.rds.amazonaws.com>"
},
{
"name": database.username,
"value": "postgres"
},
{
"name": "DEFAULT_DATABASE_PORT",
"value": "5432"
},
{
"name": "DEFAULT_DATABASE_DB",
"value": "postgres"
},
{
"name": "DEFAULT_DATABASE_PASSWORD",
"value": "G1v*y3#i13P9"
},
{
"name": "ENVIRONMENT",
"value": "STG"
}
],
secrets=[],
),
},
)
# Create a Fargate service
fargate_service = awsx.ecs.FargateService(
"TurnStayAPIService",
cluster=cluster,
task_definition=task_def,
desired_count=1,
assign_public_ip=True,
# network_configuration=aws.ecs.ServiceNetworkConfigurationArgs(
# assign_public_ip=True,
# security_groups=[web_sg.id],
# ),
)
careful-vegetable-11632
06/27/2023, 8:55 PMbillowy-army-68599
billowy-army-68599
careful-vegetable-11632
06/27/2023, 8:57 PMbillowy-army-68599
careful-vegetable-11632
06/27/2023, 8:59 PMcareful-vegetable-11632
06/27/2023, 9:05 PMbillowy-army-68599
billowy-army-68599
careful-vegetable-11632
06/28/2023, 8:11 AMcareful-vegetable-11632
06/28/2023, 8:15 AMcareful-vegetable-11632
06/28/2023, 8:15 AMbillowy-army-68599