Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
docs: add ec2 example - fix formatting (#1257)
Browse files Browse the repository at this point in the history
* Add an EC2 example with raw pulumi code

* Fix indentation

---------

Co-authored-by: Frank <[email protected]>
  • Loading branch information
agamm and fwang authored Oct 16, 2024
1 parent e442978 commit 28a3dfa
Showing 1 changed file with 44 additions and 44 deletions.
88 changes: 44 additions & 44 deletions examples/aws-ec2-pulumi/sst.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,54 @@
* Use raw Pulumi resources to create an EC2 instance.
*/
export default $config({
app(input) {
return {
name: "aws-ec2-pulumi",
home: "aws",
removal: input?.stage === "production" ? "retain" : "remove",
};
},
async run() {
// Notice you don't need to import pulumi, it is already part of sst.
const securityGroup = new aws.ec2.SecurityGroup("web-secgrp", {
ingress: [
{
protocol: "tcp",
fromPort: 80,
toPort: 80,
cidrBlocks: ["0.0.0.0/0"],
},
],
});
app(input) {
return {
name: "aws-ec2-pulumi",
home: "aws",
removal: input?.stage === "production" ? "retain" : "remove",
};
},
async run() {
// Notice you don't need to import pulumi, it is already part of sst.
const securityGroup = new aws.ec2.SecurityGroup("web-secgrp", {
ingress: [
{
protocol: "tcp",
fromPort: 80,
toPort: 80,
cidrBlocks: ["0.0.0.0/0"],
},
],
});

// Find the latest Ubuntu AMI
const ami = aws.ec2.getAmi({
filters: [
{
name: "name",
values: ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"],
},
],
mostRecent: true,
owners: ["099720109477"], // Canonical
});
// Find the latest Ubuntu AMI
const ami = aws.ec2.getAmi({
filters: [
{
name: "name",
values: ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"],
},
],
mostRecent: true,
owners: ["099720109477"], // Canonical
});

// User data to set up a simple web server
const userData = `#!/bin/bash
// User data to set up a simple web server
const userData = `#!/bin/bash
echo "Hello, World!" > index.html
nohup python3 -m http.server 80 &`;

// Create an EC2 instance
const server = new aws.ec2.Instance("web-server", {
instanceType: "t2.micro",
ami: ami.then((ami) => ami.id),
userData: userData,
vpcSecurityGroupIds: [securityGroup.id],
associatePublicIpAddress: true,
});
// Create an EC2 instance
const server = new aws.ec2.Instance("web-server", {
instanceType: "t2.micro",
ami: ami.then((ami) => ami.id),
userData: userData,
vpcSecurityGroupIds: [securityGroup.id],
associatePublicIpAddress: true,
});

return {
app: server.publicIp,
};
},
return {
app: server.publicIp,
};
},
});

0 comments on commit 28a3dfa

Please sign in to comment.