StaticIp
The StaticIp resource allows you to manage AWS Lightsail Static IPs for your instances, providing a fixed IP address that can be associated with your Lightsail resources.
Minimal Example
Section titled “Minimal Example”Create a basic Static IP with the required properties and an optional attachment.
import AWS from "alchemy/aws/control";
const staticIp = await AWS.Lightsail.StaticIp("myStaticIp", { StaticIpName: "MyStaticIp", AttachedTo: "myInstance" // Optional: Attach to an existing instance});
Advanced Configuration
Section titled “Advanced Configuration”Create a Static IP with the option to adopt an existing resource if it already exists.
const adoptStaticIp = await AWS.Lightsail.StaticIp("adoptStaticIp", { StaticIpName: "ExistingStaticIp", adopt: true // Adopt existing resource});
Detaching and Reattaching
Section titled “Detaching and Reattaching”Demonstrate how to detach a Static IP from an instance and then reattach it.
// Detach from an instanceawait AWS.Lightsail.StaticIp("detachStaticIp", { StaticIpName: "MyStaticIp", AttachedTo: undefined // Detach the Static IP});
// Reattach to a different instanceawait AWS.Lightsail.StaticIp("reattachStaticIp", { StaticIpName: "MyStaticIp", AttachedTo: "anotherInstance" // Reattach to a new instance});
Cleanup Example
Section titled “Cleanup Example”Show how to clean up by deleting a Static IP when it is no longer needed.
await AWS.Lightsail.StaticIp("deleteStaticIp", { StaticIpName: "MyStaticIp"});