all examples on this page are out-of-date (<https:...
# typescript
f
all examples on this page are out-of-date (https://www.pulumi.com/docs/guides/crosswalk/aws/ecs/#building-and-publishing-docker-images-automatically), my dependencies versions are the following:
Copy code
"dependencies": {
        "@pulumi/aws": "^5.13.0",
        "@pulumi/awsx": "^0.40.0",
        "@pulumi/pulumi": "^3.39.1"
 }
i also have attached an example error i was getting
c
Yep it does look like it's outdated. To fix the example I think something like this should work (you should be able to see the correct types using intellisense by the way):
Copy code
const image = new awsx.ecr.RepositoryImage("image", {
  repositoryUrl: repo.repository.repositoryUrl,
  ...
});
Also when you get a chance, can you please open an issue here: https://github.com/pulumi/pulumi-hugo/issues/new/choose?
f
the old
awsx.ecr.Image
allows you to specify the docker file to build from, e.g. it’s doing a build and publish action
c
Looks like your latest reply was deleted...but yeah you are right that the
RepositoryImage
isn't going to work. It's not the right thing.
f
but
awsx.ecr.RepositoryImage
only lets you specify the image name, e.g. it only takes in a string
c
yep... so the
Repository
component resource from
awsx
also has a
buildAndPushImage
method. So maybe:
Copy code
repo.buildAndPushImage({context: "./app", dockerfile: "./app/Dockerfile-multistage", cacheFrom: {stages: ["build"]}})
This will build the image and push to the repository that you are executing the
buildAndPushImage
method against.
f
c
but
awsx.ecr.RepositoryImage
only lets you specify the image name, e.g. it only takes in a string
Yeah I was wrong to ask you to use
awsx.ecr.RepositoryImage
initially. I didn't pay close attention to its constructor. The `Repository`'s
buildAndPushImage
is what you are likely looking for. You can even pass the result of that method to any
image
property that requires the ID of an image that exists in ECR.
f
no problem, what are the main differences between
pulumi/awsx
and
pulumi/aws
c
pulumi/aws
is a provider package vs.
pulumi/awsx
is a package that has hand-authored component resources. Think of
awsx
as a helpful wrapper library that does a lot behind-the-scenes for you. Some people prefer that, others want more control and so they build wrapper components themselves using
pulumi/aws
directly. As a side note, there are also Pulumi-native providers. But if you are new to Pulumi, my suggestion is to stick with
pulumi/aws
for now. But know that there is also a
pulumi/aws-native
whose goal is to offer everything that
pulumi/aws
has. It differs in its internals of how each of those packages are generated.
1
f
this is an example ECS code without any TypeScript errors for those that are interested
Copy code
import * as awsx from "@pulumi/awsx";
import * as aws from "@pulumi/aws";

// Create a repository.
const repo = new awsx.ecr.Repository("my-repo");

const image = repo.buildAndPushImage({
  context: ".",
  dockerfile: "./Dockerfile",
  cacheFrom: { stages: ["build"] },
});

// Create an ECS Cluster
const cluster = new awsx.ecs.Cluster("default-cluster");

// // Create a load balancer on port 80 and spin up two instances of Nginx.
const lb = new awsx.lb.ApplicationLoadBalancer("nginx-lb");

const service = new awsx.ecs.FargateService("my-service", {
  cluster: cluster,
  taskDefinitionArgs: {
    container: {
      image: image,
      cpu: 512,
      memory: 128,
      essential: true,
      portMappings: [
        {
          containerPort: 80,
        },
      ],
    },
  },
});

// Export the load balancer's address so that it's easy to access.
export const url = lb.loadBalancer.dnsName;
the security group that’s generated from initializing a Application Load Balancer does not have any inbound rules, is this normal?
c
I don't remember what AWSX does with SG rules, unfortunately.