1. Packages
  2. AWS
  3. API Docs
  4. lightsail
  5. InstancePublicPorts
AWS v6.77.0 published on Wednesday, Apr 9, 2025 by Pulumi

aws.lightsail.InstancePublicPorts

Explore with Pulumi AI

Opens ports for a specific Amazon Lightsail instance, and specifies the IP addresses allowed to connect to the instance through the ports, and the protocol.

See What is Amazon Lightsail? for more information.

Note: Lightsail is currently only supported in a limited number of AWS Regions, please see “Regions and Availability Zones in Amazon Lightsail” for more details.

Example Usage

import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";

const test = new aws.lightsail.Instance("test", {
    name: "yak_sail",
    availabilityZone: available.names[0],
    blueprintId: "amazon_linux_2",
    bundleId: "nano_3_0",
});
const testInstancePublicPorts = new aws.lightsail.InstancePublicPorts("test", {
    instanceName: test.name,
    portInfos: [{
        protocol: "tcp",
        fromPort: 80,
        toPort: 80,
    }],
});
Copy
import pulumi
import pulumi_aws as aws

test = aws.lightsail.Instance("test",
    name="yak_sail",
    availability_zone=available["names"][0],
    blueprint_id="amazon_linux_2",
    bundle_id="nano_3_0")
test_instance_public_ports = aws.lightsail.InstancePublicPorts("test",
    instance_name=test.name,
    port_infos=[{
        "protocol": "tcp",
        "from_port": 80,
        "to_port": 80,
    }])
Copy
package main

import (
	"github.com/pulumi/pulumi-aws/sdk/v6/go/aws/lightsail"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		test, err := lightsail.NewInstance(ctx, "test", &lightsail.InstanceArgs{
			Name:             pulumi.String("yak_sail"),
			AvailabilityZone: pulumi.Any(available.Names[0]),
			BlueprintId:      pulumi.String("amazon_linux_2"),
			BundleId:         pulumi.String("nano_3_0"),
		})
		if err != nil {
			return err
		}
		_, err = lightsail.NewInstancePublicPorts(ctx, "test", &lightsail.InstancePublicPortsArgs{
			InstanceName: test.Name,
			PortInfos: lightsail.InstancePublicPortsPortInfoArray{
				&lightsail.InstancePublicPortsPortInfoArgs{
					Protocol: pulumi.String("tcp"),
					FromPort: pulumi.Int(80),
					ToPort:   pulumi.Int(80),
				},
			},
		})
		if err != nil {
			return err
		}
		return nil
	})
}
Copy
using System.Collections.Generic;
using System.Linq;
using Pulumi;
using Aws = Pulumi.Aws;

return await Deployment.RunAsync(() => 
{
    var test = new Aws.LightSail.Instance("test", new()
    {
        Name = "yak_sail",
        AvailabilityZone = available.Names[0],
        BlueprintId = "amazon_linux_2",
        BundleId = "nano_3_0",
    });

    var testInstancePublicPorts = new Aws.LightSail.InstancePublicPorts("test", new()
    {
        InstanceName = test.Name,
        PortInfos = new[]
        {
            new Aws.LightSail.Inputs.InstancePublicPortsPortInfoArgs
            {
                Protocol = "tcp",
                FromPort = 80,
                ToPort = 80,
            },
        },
    });

});
Copy
package generated_program;

import com.pulumi.Context;
import com.pulumi.Pulumi;
import com.pulumi.core.Output;
import com.pulumi.aws.lightsail.Instance;
import com.pulumi.aws.lightsail.InstanceArgs;
import com.pulumi.aws.lightsail.InstancePublicPorts;
import com.pulumi.aws.lightsail.InstancePublicPortsArgs;
import com.pulumi.aws.lightsail.inputs.InstancePublicPortsPortInfoArgs;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;

public class App {
    public static void main(String[] args) {
        Pulumi.run(App::stack);
    }

    public static void stack(Context ctx) {
        var test = new Instance("test", InstanceArgs.builder()
            .name("yak_sail")
            .availabilityZone(available.names()[0])
            .blueprintId("amazon_linux_2")
            .bundleId("nano_3_0")
            .build());

        var testInstancePublicPorts = new InstancePublicPorts("testInstancePublicPorts", InstancePublicPortsArgs.builder()
            .instanceName(test.name())
            .portInfos(InstancePublicPortsPortInfoArgs.builder()
                .protocol("tcp")
                .fromPort(80)
                .toPort(80)
                .build())
            .build());

    }
}
Copy
resources:
  test:
    type: aws:lightsail:Instance
    properties:
      name: yak_sail
      availabilityZone: ${available.names[0]}
      blueprintId: amazon_linux_2
      bundleId: nano_3_0
  testInstancePublicPorts:
    type: aws:lightsail:InstancePublicPorts
    name: test
    properties:
      instanceName: ${test.name}
      portInfos:
        - protocol: tcp
          fromPort: 80
          toPort: 80
Copy

Create InstancePublicPorts Resource

Resources are created with functions called constructors. To learn more about declaring and configuring resources, see Resources.

Constructor syntax

new InstancePublicPorts(name: string, args: InstancePublicPortsArgs, opts?: CustomResourceOptions);
@overload
def InstancePublicPorts(resource_name: str,
                        args: InstancePublicPortsArgs,
                        opts: Optional[ResourceOptions] = None)

@overload
def InstancePublicPorts(resource_name: str,
                        opts: Optional[ResourceOptions] = None,
                        instance_name: Optional[str] = None,
                        port_infos: Optional[Sequence[InstancePublicPortsPortInfoArgs]] = None)
func NewInstancePublicPorts(ctx *Context, name string, args InstancePublicPortsArgs, opts ...ResourceOption) (*InstancePublicPorts, error)
public InstancePublicPorts(string name, InstancePublicPortsArgs args, CustomResourceOptions? opts = null)
public InstancePublicPorts(String name, InstancePublicPortsArgs args)
public InstancePublicPorts(String name, InstancePublicPortsArgs args, CustomResourceOptions options)
type: aws:lightsail:InstancePublicPorts
properties: # The arguments to resource properties.
options: # Bag of options to control resource's behavior.

Parameters

name This property is required. string
The unique name of the resource.
args This property is required. InstancePublicPortsArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
resource_name This property is required. str
The unique name of the resource.
args This property is required. InstancePublicPortsArgs
The arguments to resource properties.
opts ResourceOptions
Bag of options to control resource's behavior.
ctx Context
Context object for the current deployment.
name This property is required. string
The unique name of the resource.
args This property is required. InstancePublicPortsArgs
The arguments to resource properties.
opts ResourceOption
Bag of options to control resource's behavior.
name This property is required. string
The unique name of the resource.
args This property is required. InstancePublicPortsArgs
The arguments to resource properties.
opts CustomResourceOptions
Bag of options to control resource's behavior.
name This property is required. String
The unique name of the resource.
args This property is required. InstancePublicPortsArgs
The arguments to resource properties.
options CustomResourceOptions
Bag of options to control resource's behavior.

Constructor example

The following reference example uses placeholder values for all input properties.

var instancePublicPortsResource = new Aws.LightSail.InstancePublicPorts("instancePublicPortsResource", new()
{
    InstanceName = "string",
    PortInfos = new[]
    {
        new Aws.LightSail.Inputs.InstancePublicPortsPortInfoArgs
        {
            FromPort = 0,
            Protocol = "string",
            ToPort = 0,
            CidrListAliases = new[]
            {
                "string",
            },
            Cidrs = new[]
            {
                "string",
            },
            Ipv6Cidrs = new[]
            {
                "string",
            },
        },
    },
});
Copy
example, err := lightsail.NewInstancePublicPorts(ctx, "instancePublicPortsResource", &lightsail.InstancePublicPortsArgs{
	InstanceName: pulumi.String("string"),
	PortInfos: lightsail.InstancePublicPortsPortInfoArray{
		&lightsail.InstancePublicPortsPortInfoArgs{
			FromPort: pulumi.Int(0),
			Protocol: pulumi.String("string"),
			ToPort:   pulumi.Int(0),
			CidrListAliases: pulumi.StringArray{
				pulumi.String("string"),
			},
			Cidrs: pulumi.StringArray{
				pulumi.String("string"),
			},
			Ipv6Cidrs: pulumi.StringArray{
				pulumi.String("string"),
			},
		},
	},
})
Copy
var instancePublicPortsResource = new InstancePublicPorts("instancePublicPortsResource", InstancePublicPortsArgs.builder()
    .instanceName("string")
    .portInfos(InstancePublicPortsPortInfoArgs.builder()
        .fromPort(0)
        .protocol("string")
        .toPort(0)
        .cidrListAliases("string")
        .cidrs("string")
        .ipv6Cidrs("string")
        .build())
    .build());
Copy
instance_public_ports_resource = aws.lightsail.InstancePublicPorts("instancePublicPortsResource",
    instance_name="string",
    port_infos=[{
        "from_port": 0,
        "protocol": "string",
        "to_port": 0,
        "cidr_list_aliases": ["string"],
        "cidrs": ["string"],
        "ipv6_cidrs": ["string"],
    }])
Copy
const instancePublicPortsResource = new aws.lightsail.InstancePublicPorts("instancePublicPortsResource", {
    instanceName: "string",
    portInfos: [{
        fromPort: 0,
        protocol: "string",
        toPort: 0,
        cidrListAliases: ["string"],
        cidrs: ["string"],
        ipv6Cidrs: ["string"],
    }],
});
Copy
type: aws:lightsail:InstancePublicPorts
properties:
    instanceName: string
    portInfos:
        - cidrListAliases:
            - string
          cidrs:
            - string
          fromPort: 0
          ipv6Cidrs:
            - string
          protocol: string
          toPort: 0
Copy

InstancePublicPorts Resource Properties

To learn more about resource properties and how to use them, see Inputs and Outputs in the Architecture and Concepts docs.

Inputs

In Python, inputs that are objects can be passed either as argument classes or as dictionary literals.

The InstancePublicPorts resource accepts the following input properties:

InstanceName
This property is required.
Changes to this property will trigger replacement.
string
Name of the Lightsail Instance.
PortInfos
This property is required.
Changes to this property will trigger replacement.
List<InstancePublicPortsPortInfo>
Configuration block with port information. AWS closes all currently open ports that are not included in the port_info. Detailed below.
InstanceName
This property is required.
Changes to this property will trigger replacement.
string
Name of the Lightsail Instance.
PortInfos
This property is required.
Changes to this property will trigger replacement.
[]InstancePublicPortsPortInfoArgs
Configuration block with port information. AWS closes all currently open ports that are not included in the port_info. Detailed below.
instanceName
This property is required.
Changes to this property will trigger replacement.
String
Name of the Lightsail Instance.
portInfos
This property is required.
Changes to this property will trigger replacement.
List<InstancePublicPortsPortInfo>
Configuration block with port information. AWS closes all currently open ports that are not included in the port_info. Detailed below.
instanceName
This property is required.
Changes to this property will trigger replacement.
string
Name of the Lightsail Instance.
portInfos
This property is required.
Changes to this property will trigger replacement.
InstancePublicPortsPortInfo[]
Configuration block with port information. AWS closes all currently open ports that are not included in the port_info. Detailed below.
instance_name
This property is required.
Changes to this property will trigger replacement.
str
Name of the Lightsail Instance.
port_infos
This property is required.
Changes to this property will trigger replacement.
Sequence[InstancePublicPortsPortInfoArgs]
Configuration block with port information. AWS closes all currently open ports that are not included in the port_info. Detailed below.
instanceName
This property is required.
Changes to this property will trigger replacement.
String
Name of the Lightsail Instance.
portInfos
This property is required.
Changes to this property will trigger replacement.
List<Property Map>
Configuration block with port information. AWS closes all currently open ports that are not included in the port_info. Detailed below.

Outputs

All input properties are implicitly available as output properties. Additionally, the InstancePublicPorts resource produces the following output properties:

Id string
The provider-assigned unique ID for this managed resource.
Id string
The provider-assigned unique ID for this managed resource.
id String
The provider-assigned unique ID for this managed resource.
id string
The provider-assigned unique ID for this managed resource.
id str
The provider-assigned unique ID for this managed resource.
id String
The provider-assigned unique ID for this managed resource.

Look up Existing InstancePublicPorts Resource

Get an existing InstancePublicPorts resource’s state with the given name, ID, and optional extra properties used to qualify the lookup.

public static get(name: string, id: Input<ID>, state?: InstancePublicPortsState, opts?: CustomResourceOptions): InstancePublicPorts
@staticmethod
def get(resource_name: str,
        id: str,
        opts: Optional[ResourceOptions] = None,
        instance_name: Optional[str] = None,
        port_infos: Optional[Sequence[InstancePublicPortsPortInfoArgs]] = None) -> InstancePublicPorts
func GetInstancePublicPorts(ctx *Context, name string, id IDInput, state *InstancePublicPortsState, opts ...ResourceOption) (*InstancePublicPorts, error)
public static InstancePublicPorts Get(string name, Input<string> id, InstancePublicPortsState? state, CustomResourceOptions? opts = null)
public static InstancePublicPorts get(String name, Output<String> id, InstancePublicPortsState state, CustomResourceOptions options)
resources:  _:    type: aws:lightsail:InstancePublicPorts    get:      id: ${id}
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
resource_name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
name This property is required.
The unique name of the resulting resource.
id This property is required.
The unique provider ID of the resource to lookup.
state
Any extra arguments used during the lookup.
opts
A bag of options that control this resource's behavior.
The following state arguments are supported:
InstanceName Changes to this property will trigger replacement. string
Name of the Lightsail Instance.
PortInfos Changes to this property will trigger replacement. List<InstancePublicPortsPortInfo>
Configuration block with port information. AWS closes all currently open ports that are not included in the port_info. Detailed below.
InstanceName Changes to this property will trigger replacement. string
Name of the Lightsail Instance.
PortInfos Changes to this property will trigger replacement. []InstancePublicPortsPortInfoArgs
Configuration block with port information. AWS closes all currently open ports that are not included in the port_info. Detailed below.
instanceName Changes to this property will trigger replacement. String
Name of the Lightsail Instance.
portInfos Changes to this property will trigger replacement. List<InstancePublicPortsPortInfo>
Configuration block with port information. AWS closes all currently open ports that are not included in the port_info. Detailed below.
instanceName Changes to this property will trigger replacement. string
Name of the Lightsail Instance.
portInfos Changes to this property will trigger replacement. InstancePublicPortsPortInfo[]
Configuration block with port information. AWS closes all currently open ports that are not included in the port_info. Detailed below.
instance_name Changes to this property will trigger replacement. str
Name of the Lightsail Instance.
port_infos Changes to this property will trigger replacement. Sequence[InstancePublicPortsPortInfoArgs]
Configuration block with port information. AWS closes all currently open ports that are not included in the port_info. Detailed below.
instanceName Changes to this property will trigger replacement. String
Name of the Lightsail Instance.
portInfos Changes to this property will trigger replacement. List<Property Map>
Configuration block with port information. AWS closes all currently open ports that are not included in the port_info. Detailed below.

Supporting Types

InstancePublicPortsPortInfo
, InstancePublicPortsPortInfoArgs

FromPort
This property is required.
Changes to this property will trigger replacement.
int
First port in a range of open ports on an instance.
Protocol
This property is required.
Changes to this property will trigger replacement.
string
IP protocol name. Valid values are tcp, all, udp, and icmp.
ToPort
This property is required.
Changes to this property will trigger replacement.
int

Last port in a range of open ports on an instance.

The following arguments are optional:

CidrListAliases List<string>
Set of CIDR aliases that define access for a preconfigured range of IP addresses.
Cidrs List<string>
Set of CIDR blocks.
Ipv6Cidrs List<string>
FromPort
This property is required.
Changes to this property will trigger replacement.
int
First port in a range of open ports on an instance.
Protocol
This property is required.
Changes to this property will trigger replacement.
string
IP protocol name. Valid values are tcp, all, udp, and icmp.
ToPort
This property is required.
Changes to this property will trigger replacement.
int

Last port in a range of open ports on an instance.

The following arguments are optional:

CidrListAliases []string
Set of CIDR aliases that define access for a preconfigured range of IP addresses.
Cidrs []string
Set of CIDR blocks.
Ipv6Cidrs []string
fromPort
This property is required.
Changes to this property will trigger replacement.
Integer
First port in a range of open ports on an instance.
protocol
This property is required.
Changes to this property will trigger replacement.
String
IP protocol name. Valid values are tcp, all, udp, and icmp.
toPort
This property is required.
Changes to this property will trigger replacement.
Integer

Last port in a range of open ports on an instance.

The following arguments are optional:

cidrListAliases List<String>
Set of CIDR aliases that define access for a preconfigured range of IP addresses.
cidrs List<String>
Set of CIDR blocks.
ipv6Cidrs List<String>
fromPort
This property is required.
Changes to this property will trigger replacement.
number
First port in a range of open ports on an instance.
protocol
This property is required.
Changes to this property will trigger replacement.
string
IP protocol name. Valid values are tcp, all, udp, and icmp.
toPort
This property is required.
Changes to this property will trigger replacement.
number

Last port in a range of open ports on an instance.

The following arguments are optional:

cidrListAliases string[]
Set of CIDR aliases that define access for a preconfigured range of IP addresses.
cidrs string[]
Set of CIDR blocks.
ipv6Cidrs string[]
from_port
This property is required.
Changes to this property will trigger replacement.
int
First port in a range of open ports on an instance.
protocol
This property is required.
Changes to this property will trigger replacement.
str
IP protocol name. Valid values are tcp, all, udp, and icmp.
to_port
This property is required.
Changes to this property will trigger replacement.
int

Last port in a range of open ports on an instance.

The following arguments are optional:

cidr_list_aliases Sequence[str]
Set of CIDR aliases that define access for a preconfigured range of IP addresses.
cidrs Sequence[str]
Set of CIDR blocks.
ipv6_cidrs Sequence[str]
fromPort
This property is required.
Changes to this property will trigger replacement.
Number
First port in a range of open ports on an instance.
protocol
This property is required.
Changes to this property will trigger replacement.
String
IP protocol name. Valid values are tcp, all, udp, and icmp.
toPort
This property is required.
Changes to this property will trigger replacement.
Number

Last port in a range of open ports on an instance.

The following arguments are optional:

cidrListAliases List<String>
Set of CIDR aliases that define access for a preconfigured range of IP addresses.
cidrs List<String>
Set of CIDR blocks.
ipv6Cidrs List<String>

Package Details

Repository
AWS Classic pulumi/pulumi-aws
License
Apache-2.0
Notes
This Pulumi package is based on the aws Terraform Provider.