(Construct scope, string id, IStackProps props = null)
| 15 | |
| 16 | |
| 17 | internal PollyStack(Construct scope, string id, IStackProps props = null) : base(scope, id, props) |
| 18 | { |
| 19 | // Lambda Function that takes in text and returns a polly voice synthesis |
| 20 | _pollyFunction = new Lambda.Function(this, "pollyHandler", new Lambda.FunctionProps |
| 21 | { |
| 22 | Runtime = Lambda.Runtime.PYTHON_3_8, |
| 23 | Code = Lambda.Code.FromAsset("lambda_fns"), |
| 24 | Handler = "polly.handler" |
| 25 | }); |
| 26 | |
| 27 | // https://docs.aws.amazon.com/polly/latest/dg/api-permissions-reference.html |
| 28 | // https://docs.aws.amazon.com/translate/latest/dg/translate-api-permissions-ref.html |
| 29 | _pollyPolicy = new IAM.PolicyStatement(new IAM.PolicyStatementProps |
| 30 | { |
| 31 | Effect = IAM.Effect.ALLOW, |
| 32 | Resources = new[] { "*" }, |
| 33 | Actions = new[] |
| 34 | { |
| 35 | "translate:TranslateText", "polly:SynthesizeSpeech" |
| 36 | } |
| 37 | }); |
| 38 | |
| 39 | _pollyFunction.AddToRolePolicy(_pollyPolicy); |
| 40 | |
| 41 | // defines an API Gateway Http API resource backed by our "pollyHandler" function. |
| 42 | _httpApi = new APIGatewayV2.HttpApi(this, "Polly", new APIGatewayV2.HttpApiProps |
| 43 | { |
| 44 | DefaultIntegration = new APIGatewayV2Integrations.LambdaProxyIntegration( |
| 45 | new APIGatewayV2Integrations.LambdaProxyIntegrationProps |
| 46 | { |
| 47 | Handler = _pollyFunction |
| 48 | }) |
| 49 | }); |
| 50 | |
| 51 | new CfnOutput(this, "HTTP API Url", new CfnOutputProps |
| 52 | { |
| 53 | Value = _httpApi.Url |
| 54 | }); |
| 55 | } |
| 56 | } |
| 57 | } |
nothing calls this directly
no outgoing calls
no test coverage detected