{"id":32150515,"url":"https://github.com/swift-cloud/swift-cloud","last_synced_at":"2026-03-02T22:19:59.809Z","repository":{"id":252243317,"uuid":"838064732","full_name":"swift-cloud/swift-cloud","owner":"swift-cloud","description":"Swift Infrastructure as Code","archived":false,"fork":false,"pushed_at":"2025-11-26T22:14:07.000Z","size":707,"stargazers_count":155,"open_issues_count":1,"forks_count":10,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-11-29T17:30:43.561Z","etag":null,"topics":["aws","iac","linux","macos","serverless","swift"],"latest_commit_sha":null,"homepage":"https://swiftpackageindex.com/swift-cloud/swift-cloud/documentation","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/swift-cloud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-08-04T20:47:22.000Z","updated_at":"2025-11-26T22:14:12.000Z","dependencies_parsed_at":"2024-08-23T03:34:19.055Z","dependency_job_id":"9d8c7827-7f43-43d7-a399-074727ac9e70","html_url":"https://github.com/swift-cloud/swift-cloud","commit_stats":null,"previous_names":["swift-cloud/swift-cloud"],"tags_count":37,"template":false,"template_full_name":null,"purl":"pkg:github/swift-cloud/swift-cloud","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swift-cloud%2Fswift-cloud","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swift-cloud%2Fswift-cloud/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swift-cloud%2Fswift-cloud/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swift-cloud%2Fswift-cloud/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/swift-cloud","download_url":"https://codeload.github.com/swift-cloud/swift-cloud/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/swift-cloud%2Fswift-cloud/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29622034,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-19T13:04:20.082Z","status":"ssl_error","status_checked_at":"2026-02-19T13:03:33.775Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aws","iac","linux","macos","serverless","swift"],"created_at":"2025-10-21T10:03:04.959Z","updated_at":"2026-03-02T22:19:59.803Z","avatar_url":"https://github.com/swift-cloud.png","language":"Swift","readme":"# Swift Cloud\n\nSwift Infrastructure as Code\n\nThe fastest way to build and deploy server side Swift applications.\n\nSwift Cloud is based on the premise that infrastructure should be defined along\nside your application, in the same language as your application. In our case,\nSwift. Define a new target, describe your infrastructure, and deploy it with a\nsingle command. There's no Dockerfiles, no Terrafrom configurations, no Node.js\npackages. Everything is defined in Swift and the complex configuration is\nhandled behind the scenes, using modern architecture best practices.\n\n```swift\nlet jobHandler = AWS.Function(\n    \"job-handler\",\n    targetName: \"JobProcessor\",\n    memory: 512,\n    timeout: .seconds(10)\n)\n\nlet queue = AWS.Queue(\"job-queue\")\n\nqueue.subscribe(jobHandler)\n\nlet server = AWS.WebServer(\n    \"hummingbird-server\",\n    targetName: \"App\",\n    concurrency: 1,\n    autoScaling: .init(\n        maximumConcurrency: 10,\n        metrics: [.cpu(50), .memory(50)]\n    )\n)\n\nserver.link(queue)\n```\n\n```sh\nswift run Infra deploy --stage production\n```\n\n## How it works\n\nThe Swift Cloud package is powered by [Pulumi](https://www.pulumi.com).\nSpecifically, the SDK vends Swift components that are compiled into Pulumi YAML\nfiles, and then the Pulumi CLI is used to deploy your application. You do not\nneed a Pulumi account to use Swift Cloud, nor do you need to install Pulumi CLI\non your machine. Everything is managed by the SDK and written to a `.cloud`\ndirectory in your project.\n\n## Get Started\n\n### Prepare your environment\n\n#### Setup Docker\n\nIn order to use Swift Cloud you need to have Docker installed on your machine.\nThis is a short term limitation until Swift 6 where we will be able to natively\ncross-compile to Linux and other SDKs.\n\nIf you're on a Mac the easiest way to install Docker is\n[OrbStack](https://orbstack.dev). Simply download OrbStack and run the\ninstaller.\n\n#### Setup AWS\n\nYou will need to have an AWS account and AWS credentials loaded on your machine\nor in the typical environment variables.\n\n```bash\nexport AWS_ACCESS_KEY_ID=...\nexport AWS_SECRET_ACCESS_KEY=...\n```\n\nYou can also provide a `.env` file in the root of your project with the same\nrelevant variables.\n\nIf you're on a Mac the easiest way to manage your AWS credentials is\n[Leapp](https://www.leapp.cloud).\n\nYou can also use the AWS CLI to configure your credentials:\n\n```bash\naws configure\n```\n\n### Add to your project\n\n```swift\ndependencies: [\n    .package(url: \"https://github.com/swift-cloud/swift-cloud.git\", branch: \"main\")\n]\n```\n\n### Define your infrastructure\n\nSwift Cloud works by declaring your infrastructure as Swift code. To do this you\nmust create a new executable target in the same package as your application.\n\nStart by defining a new executable target in your `Package.swift` file:\n\n```swift\ntargets: [\n    ...\n    .executableTarget(\n        name: \"Infra\",\n        dependencies: [\n            .product(name: \"Cloud\", package: \"swift-cloud\")\n        ]\n    )\n]\n```\n\nNext, inside your `Sources` directory create a new folder called `Infra`.\n\nFinally, add a new Swift file called `Project.swift`:\n\n```swift\nimport Cloud\n\n@main\nstruct SwiftCloudDemo: AWSProject {\n    func build() async throws -\u003e Outputs {\n        let server = AWS.WebServer(\n            \"my-vapor-web-server\",\n            targetName: \"App\",\n            concurrency: 1,\n            autoScaling: .init(\n                maximumConcurrency: 10,\n                metrics: [.cpu(50), .memory(50)]\n            )\n        )\n\n        return Outputs([\n            \"url\": server.url,\n        ])\n    }\n}\n```\n\n### Deploy your project\n\n```bash\nswift run Infra deploy --stage production\n```\n\n## Commands\n\nSwift Cloud is invoked directly from your Swift package. You can run the\nfollowing commands:\n\n### Deploy\n\nDeploy your infrastructure:\n\n```bash\nswift run Infra deploy --stage production\n```\n\n### Remove\n\nRemove all resources:\n\n```bash\nswift run Infra remove --stage development\n```\n\n### Preview\n\nPreview changes before deploying:\n\n```bash\nswift run Infra preview --stage development\n```\n\n### Outputs\n\nShow the outputs of your deployment:\n\n```bash\nswift run Infra outputs --stage development\n```\n\n### Cancel\n\nCancel a deployment:\n\n```bash\nswift run Infra cancel --stage development\n```\n\n## Home\n\nSwift Cloud allows you to deploy infrastructure across multiple cloud providers.\nIn order to handle incremental changes to your infrastructure, Swift Cloud must\nstore your underlying configuration in a durable location so it can be\nreferenced anytime you run a deploy, whether from your local machine or a CI/CD\npipeline.\n\nWe abstracted this concept into a `HomeProvider` protocol, and allow you to\ndecide where your configuration is stored. By default, Swift Cloud uses the AWS\nS3 service to store your configuration, but you can easily swap this out for any\nother provider that supports the `HomeProvider` protocol.\n\nFor quick prototyping, you can use the `Home.Local` provider, which stores your\nconfiguration in a local file. This is great for testing and development, but\nit's not recommended for production use.\n\n```swift\nimport Cloud\n\n@main\nstruct SwiftCloudDemo: AWSProject {\n\n    // Override the default home provider with a local provider\n    let home = Home.Local()\n\n    func build() async throws -\u003e Outputs {...}\n}\n```\n\n## Components\n\n### AWS\n\n#### WebServer\n\nThis component creates a high performance web server using an application load\nbalancer, auto-scaling group, and Fargate. Everything is fully managed and\nscales automatically based on your configuration.\n\n```swift\nlet server = AWS.WebServer(\n    \"my-vapor-web-server\",\n    targetName: \"App\",\n    concurrency: 1,\n    autoScaling: .init(\n        maximumConcurrency: 10,\n        metrics: [.cpu(50), .memory(50)]\n    )\n)\n```\n\n#### Function\n\n```swift\nlet lambda = AWS.Function(\n    \"my-lambda-function\",\n    targetName: \"App\",\n    url: .enabled(cors: true),\n    memory: 512,\n    timeout: .seconds(10)\n)\n\n// Optional: build with the static Linux SDK instead of Docker\nlet staticLambda = AWS.Function(\n    \"my-static-lambda-function\",\n    targetName: \"App\",\n    runtime: .al2023,\n    build: .staticLinuxSDK\n)\n```\n\n#### CDN\n\nThis component creates a CDN that sits in front of your application. It can be\nused to cache your application assets, or to serve your application from a\ncustom domain.\n\n```swift\nlet cdn = AWS.CDN(\n    \"my-cdn\",\n    origins: .webServer(server)\n)\n```\n\nYou can also route traffic on different paths to different resources:\n\n```swift\nlet cdn = AWS.CDN(\n    \"my-cdn\",\n    origins: [\n        .function(function, path: \"/api/*\"),\n        .webServer(server, path: \"*\")\n    ]\n)\n```\n\nAnd of course you can use a custom domain:\n\n```swift\nlet cdn = AWS.CDN(\n    \"my-cdn\",\n    origins: .function(function),\n    domainName: .init(\"www.example.com\")\n)\n```\n\n#### Bucket\n\n```swift\nlet bucket = AWS.Bucket(\"my-s3-bucket\")\n```\n\n#### Queue\n\n```swift\nlet queue = AWS.Queue(\"my-sqs-queue\")\n\n// Subscribe a lambda function to the queue to process messages\nqueue.subscribe(\n    AWS.Function(\"my-lambda-function\", targetName: \"App\")\n)\n```\n\n#### DynamoDB\n\n```swift\nlet table = AWS.DynamoDB(\n    \"MyTable\",\n    primaryIndex: .init(\n        partitionKey: (\"type\", .string),\n        sortKey: (\"id\", .string)\n    )\n)\n\n// Link the table to a function or web server\nfunction.link(table)\n```\n\n#### Cache\n\n```swift\nlet vpc = AWS.VPC(\"my-vpc\")\n\nlet cache = AWS.Cache(\n    \"my-valkey-cache\",\n    engine: .valkey(), // or .redis() or .memcached()\n    vpc: .private(vpc)\n)\n\n// Allow the function or web server to connect to the cache\nfunction.link(cache)\n```\n\n#### SQL Database\n\n```swift\nlet database = AWS.SQLDatabase(\n    \"my-postgres-database\",\n    engine: .postgres(),\n    vpc: .private(vpc)\n)\n\n// Allow the function or web server to connect to the database\nfunction.link(database)\n```\n\n#### Aurora DSQL\n\n```swift\nlet east = AWS.DSQL.Cluster(\n    \"orders-east\",\n    region: \"us-east-1\",\n    multiRegion: .enabled(witnessRegion: \"us-west-2\")\n)\n\nlet west = AWS.DSQL.Cluster(\n    \"orders-west\",\n    region: \"us-east-2\",\n    multiRegion: .enabled(witnessRegion: \"us-west-2\")\n)\n\n// Creates both directional aws:dsql:ClusterPeering resources\neast.peer(with: west)\n```\n\n#### Topic\n\n```swift\nlet topic = AWS.Topic(\"my-sns-topic\")\n\n// Subscribe a lambda function to the topic to process events\ntopic.subscribe(\n    AWS.Function(\"my-lambda-function\", targetName: \"App\")\n)\n```\n\n#### Cron\n\n```swift\nlet cron = AWS.Cron(\n    \"my-cron-job\",\n    schedule: .rate(.minutes(5))\n)\n\n// Invoke the function when the cron job runs\ncron.invoke(\n    AWS.Function(\"my-lambda-function\", targetName: \"App\")\n)\n```\n\n#### Domain Name\n\nThe `DomainName` construct manages a TLS certificate and the necessary\nvalidation, and can be linked to a `WebServer` to provide a fully managed domain\nname.\n\n\u003e [!IMPORTANT]\n\u003e SwiftCloud supports 3 providers for domains: **AWS**, **Cloudflare**, and **Vercel**.\n\n```swift\nlet domainName = DomainName(\n    hostname: \"www.example.com\",\n    dns: .aws(zoneName: \"example.com\")\n)\n\nlet server = AWS.WebServer(\n    \"my-vapor-web-server\",\n    targetName: \"App\",\n    domainName: domainName\n)\n\nreturn Outputs([\n    // Now server url will be `https://www.example.com`\n    \"url\": server.url\n])\n```\n\n### Linking\n\nYou can link resources together to provide the necessary permissions to access\neach other. This is more secure than sharing access key ids and secrets in\nenvironment variables.\n\nFor example you can link an S3 bucket to a Lambda function:\n\n```swift\nmyFunction.link(bucket)\n```\n\nThis allows the lambda function to access the bucket without needing to share\naccess keys.\n\n#### Using linked resources\n\nYou can use linked resources in your server or function via environment\nvariables in your application:\n\n```swift\nlet bucketUrl = ProcessInfo.processInfo.environment[\"BUCKET_MEDIA_URL\"]\n```\n\nHere is a list of all the linked resources:\n\n| Resource            | Environment Variable         |\n| ------------------- | ---------------------------- |\n| AWS S3 Bucket       | `BUCKET_\u003cNAME\u003e_URL`          |\n| AWS S3 Bucket       | `BUCKET_\u003cNAME\u003e_HOSTNAME`     |\n| AWS S3 Bucket       | `BUCKET_\u003cNAME\u003e_NAME`         |\n| AWS SQS Queue       | `QUEUE_\u003cNAME\u003e_URL`           |\n| AWS SQS Queue       | `QUEUE_\u003cNAME\u003e_NAME`          |\n| AWS Lambda Function | `FUNCTION_\u003cNAME\u003e_URL`        |\n| AWS Lambda Function | `FUNCTION_\u003cNAME\u003e_NAME`       |\n| AWS DynamoDB Table  | `DYNAMODB_\u003cNAME\u003e_NAME`       |\n| AWS Cache           | `CACHE_\u003cNAME\u003e_HOSTNAME`      |\n| AWS Cache           | `CACHE_\u003cNAME\u003e_PORT`          |\n| AWS Cache           | `CACHE_\u003cNAME\u003e_URL`           |\n| AWS SQL Database    | `SQLDB_\u003cNAME\u003e_HOSTNAME`      |\n| AWS SQL Database    | `SQLDB_\u003cNAME\u003e_PORT`          |\n| AWS SQL Database    | `SQLDB_\u003cNAME\u003e_DATABASE_NAME` |\n| AWS SQL Database    | `SQLDB_\u003cNAME\u003e_USERNAME`      |\n| AWS SQL Database    | `SQLDB_\u003cNAME\u003e_PASSWORD`      |\n| AWS SQL Database    | `SQLDB_\u003cNAME\u003e_URL`           |\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswift-cloud%2Fswift-cloud","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fswift-cloud%2Fswift-cloud","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fswift-cloud%2Fswift-cloud/lists"}