Created
July 29, 2021 14:13
-
-
Save newhouseb/1944cf4bdeeb5bc799bc327fc8a25f59 to your computer and use it in GitHub Desktop.
Rust + AWS Lambda + Pulumi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Lambda/Web configuration | |
*/ | |
const robocontrollerRole = new aws.iam.Role("robocontrollerRole", { | |
assumeRolePolicy: aws.iam.assumeRolePolicyForPrincipal({ Service: "lambda.amazonaws.com" }), | |
}); | |
const lambdaRole = new aws.iam.RolePolicyAttachment("executeLambdaRoleAttach", { | |
role: robocontrollerRole, | |
policyArn: aws.iam.ManagedPolicies.AWSLambdaExecute, | |
}); | |
const lambdaVPC = new aws.iam.RolePolicyAttachment("attachVPCRoleAttach", { | |
role: robocontrollerRole, | |
policyArn: aws.iam.ManagedPolicies.AWSLambdaVPCAccessExecutionRole, | |
}); | |
const lambda = new aws.lambda.Function("robocontroller", { | |
code: new pulumi.asset.AssetArchive({ | |
'bootstrap': new pulumi.asset.FileAsset('../backend/target/x86_64-unknown-linux-musl/release/robocontroller2') | |
}), | |
handler: "thisisabug", | |
runtime: "provided.al2", | |
role: robocontrollerRole.arn, | |
vpcConfig: { | |
securityGroupIds: [web_sg.id], | |
subnetIds: vpc.publicSubnetIds | |
} | |
}) | |
const apiGateway = new aws.apigatewayv2.Api("rc-api-gateway", { | |
protocolType: "HTTP", | |
}); | |
const lambdaPermission = new aws.lambda.Permission("lambdaPermission", { | |
action: "lambda:InvokeFunction", | |
principal: "apigateway.amazonaws.com", | |
function: lambda, | |
sourceArn: pulumi.interpolate`${apiGateway.executionArn}/*/*`, | |
}, {dependsOn: [apiGateway, lambda]}); | |
const integration = new aws.apigatewayv2.Integration("proxyIntegration", { | |
apiId: apiGateway.id, | |
integrationType: "AWS_PROXY", | |
connectionType: "INTERNET", | |
description: "API", | |
integrationMethod: "ANY", | |
integrationUri: lambda.arn, | |
payloadFormatVersion: "2.0", | |
passthroughBehavior: "WHEN_NO_MATCH", | |
}); | |
const route = new aws.apigatewayv2.Route("apiRoute", { | |
apiId: apiGateway.id, | |
routeKey: "$default", | |
target: pulumi.interpolate`integrations/${integration.id}`, | |
}); | |
const stage = new aws.apigatewayv2.Stage("apiStage", { | |
apiId: apiGateway.id, | |
name: "prod", | |
routeSettings: [ | |
{ | |
routeKey: route.routeKey, | |
throttlingBurstLimit: 5000, | |
throttlingRateLimit: 10000, | |
}, | |
], | |
autoDeploy: true, | |
}, {dependsOn: [route]}); | |
export const apiEndpoint = pulumi.interpolate`${apiGateway.apiEndpoint}/${stage.name}`; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment