At re:Invent, AWS introduced the ability to run EKS pods on AWS Fargate, and Fargate is cheaper than hosting Kubernetes yourself. In the last post I created an EKS cluster, so this one adds a Fargate profile to it.
The complete project is available on GitHub.
Configuration #
The Fargate profile needs a name, a Kubernetes namespace to target, and an IAM role for pod execution. Add this to the YAML file from the previous post:
fargate:profile-name: EKSFargateProfile
fargate:namespace: example
fargate:execution-role-arn: "arn:aws:iam::ACCOUNTID:role/EKSFargatePodExecutionRole"For details on creating the IAM role, check the AWS docs. You can use the command line (e.g., pulumi config set fargate:profile-name "EKSFargateProfile") or edit the YAML file directly. The file is named Pulumi.<name of your project>.yaml.
Adding the Fargate profile #
This code extends the previous post. It reads the profile name and namespace from the YAML file, references the cluster and subnets from earlier posts, and calls eks.NewFargateProfile() to attach the profile to your cluster.
// Create an EKS Fargate Profile
fargateProfileName := getEnv(ctx, "fargate:profile-name", "unknown")
selectors := make([]map[string]interface{}, 1)
namespaces := make(map[string]interface{})
namespaces["namespace"] = getEnv(ctx, "fargate:namespace", "unknown")
selectors[0] = namespaces
fargateProfileArgs := &eks.FargateProfileArgs{
ClusterName: clusterName,
FargateProfileName: fargateProfileName,
Tags: tags,
SubnetIds: subnets["subnet_ids"],
Selectors: selectors,
PodExecutionRoleArn: getEnv(ctx, "fargate:execution-role-arn", "unknown"),
}
fargateProfile, err := eks.NewFargateProfile(ctx, fargateProfileName, fargateProfileArgs)
if err != nil {
fmt.Println(err.Error())
return err
}
ctx.Export("FARGATE-PROFILE-ID", fargateProfile.ID())Running the code #
Run pulumi up to add the Fargate profile. If you’re using the same project and stack, Pulumi knows the cluster already exists and will only create the new profile.
$ pulumi up
Previewing update (builderstack):
Type Name Plan
pulumi:pulumi:Stack builder-builderstack
+ └─ aws:eks:FargateProfile EKSFargateProfile create
Outputs:
+ FARGATE-PROFILE-ID: output<string>
Resources:
+ 1 to create
5 unchanged
Do you want to perform this update? yes
Updating (builderstack):
Type Name Status
pulumi:pulumi:Stack builder-builderstack
+ └─ aws:eks:FargateProfile EKSFargateProfile created
Outputs:
CLUSTER-ID : "myEKSCluster"
+ FARGATE-PROFILE-ID: "myEKSCluster:EKSFargateProfile"
SUBNET-IDS : [
[0]: "subnet-0a1909bec2e936bd7"
[1]: "subnet-09d229c2eb8061979"
]
VPC-ID : "vpc-0437c750acf1050c3"
Resources:
+ 1 created
5 unchanged
Duration: 2m27s
Permalink: https://app.pulumi.com/retgits/builder/builderstack/updates/4The permalink at the bottom takes you to the Pulumi console where you can see all the details of the execution and the resources that were created.

Cover image by Gerd Altmann from Pixabay