Skip to content

Instantly share code, notes, and snippets.

@marklam
Created January 22, 2020 13:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marklam/ad8a0aa61b17e103fa8adc63c162c988 to your computer and use it in GitHub Desktop.
Save marklam/ad8a0aa61b17e103fa8adc63c162c988 to your computer and use it in GitHub Desktop.
Pulumi FSharp code to create an API gateway entry for a lambda function that's hosting Asp.net core (eg in giraffe)
let infra () =
...
let openApiSpec (name, arn) =
let quotedTitle = "\"" + name + "api\""
let quotedUri = sprintf "\"arn:aws:apigateway:%s:lambda:path/2015-03-31/functions/%s/invocations\"" Pulumi.Aws.Config.Region arn
"""{
"openapi": "3.0.1",
"info": {
"title": """ + quotedTitle + """,
"version": "1.0"
},
"paths": {
"/{proxy+}": {
"x-amazon-apigateway-any-method": {
"x-amazon-apigateway-integration": {
"uri": """ + quotedUri + """,
"passthroughBehavior": "when_no_match",
"httpMethod": "POST",
"type": "aws_proxy"
}
}
},
"/": {
"x-amazon-apigateway-any-method": {
"x-amazon-apigateway-integration": {
"uri": """ + quotedUri + """,
"passthroughBehavior": "when_no_match",
"httpMethod": "POST",
"type": "aws_proxy"
}
}
}
},
"components": {}
}"""
let restApiArgs lambdaName lambdaArn =
let openApiSpec =
Outputs.pair lambdaName lambdaArn
|> Outputs.apply openApiSpec
RestApiArgs(Body = io openApiSpec)
let restApi = RestApi("websiteApi", (restApiArgs websiteLambda.Name websiteLambda.Arn))
let deployment = Deployment("websiteApiDeployment", DeploymentArgs(RestApi = io restApi.Id, StageName = input ""))
let prodStage = Stage("websiteApiProd", StageArgs(RestApi = io restApi.Id, Deployment = io deployment.Id, StageName = input "Prod"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment