如何提供API网关集成授权来调用Lambda函数?

时间:2020-09-30 21:45:39

标签: aws-lambda aws-api-gateway aws-cli

在设置API以从AWS API Gateway UI控制台调用AWS Lambda函数时,系统会询问您是否授予API Gateway调用Lambda函数的权限。

通过 AWS CLI 进行操作时有什么等效功能?

我已经设置了两种资源和两种方法-一种通过控制台,一种通过命令行。

当我通过控制台调用一个设置时,它工作正常。

但是当我通过CLI调用设置时,我会得到响应

<Columns>
 <asp:TemplateField HeaderText="Instrument #, Type, Dist., Squ. , Lot">
                       <ItemTemplate>
                            <asp:LinkButton ID="LbPath" runat="server" 
                               Text='<%# String.Format("{0} {1}", Eval("InstrumentNumber"), Eval("InstrumentType")) %>' 
                                CommandName="GetInstrument" 
                                CommandArgument='<%#Bind("instrumentID") %>'>
                            </asp:LinkButton>
                           <br />
                           <asp:Label ID="lblDateFiled" runat="server" Text='<%# Eval("DateTimeFiled") %>'> </asp:Label>
                             <br />
                            <asp:Label ID="lblNANumber" runat="server" Font-Names="Segoe UI Semibold" Font-Size="Medium" Text="NA Number: " ForeColor="#434343"></asp:Label><%# Eval("NANumber") %>
                           <br />
                           <br />
                           <asp:Label ID="lblDSL" runat="server" Text='<%#Eval("DSL") %>'> </asp:Label> 
                            <%--<asp:Label ID="lblDSL" runat="server" Text='<%# String.Format("{0} {1} {2}", Eval("District"), Eval("Square"),  Eval("Lot")) %>'> </asp:Label> --%>                           
                        </ItemTemplate>
                   </asp:TemplateField>
                        <asp:TemplateField HeaderText="Name, Address" SortExpression="Surname">
                <ItemTemplate>
                    <EditItemTemplate>
                        
                   <%-- <asp:Label ID="label1"  runat="server" Text='<%# Bind("instrumentID") %>' ></asp:Label>--%>
                </EditItemTemplate>
                                    <asp:Label ID="lblName" runat="server" Text='<%#  Eval("Name") %>'></asp:Label>
<%--                    <asp:Label ID="lblName" runat="server" Text='<%# String.Format(" {0}, {1} ({2})", Eval("Surname"), Eval("GivenName"), Eval("Namecode")) %>'></asp:Label>--%>
                    <br />
                    <asp:Label ID="lblAddress" runat="server" Font-Names="Segoe UI Semibold" Font-Size="Medium" Text='<%# Eval("Address") %>'></asp:Label>
                   <%--<asp:Label ID="lblAddress" runat="server" Font-Names="Segoe UI Semibold" Font-Size="Medium" Text='<%# String.Format("{0} {1} {2}", Eval("Subdivision"), Eval("StreetNumber"), Eval("StreetName")) %>'></asp:Label>--%>
                </ItemTemplate>
            </asp:TemplateField>
                  <%-- <asp:BoundField DataField="InstrumentType" HeaderText="Instrument Type" InsertVisible="false" ReadOnly="true" SortExpression="InstrumentType" />
                   <asp:BoundField DataField="NANumber" HeaderText="NANumber" InsertVisible="false" SortExpression="NANumber" />
                   <asp:BoundField DataField="DateTimeFiled" HeaderText="DateTimeFiled" InsertVisible="false" ReadOnly="true" SortExpression="DateTimeFiled" />--%>

               </Columns>

如果我通过API网关测试功能对其进行测试,我会看到

url = "https://youtu.be/mRe-514tGMg"
camera_source = pafy.new(url).getbest()
capture = cv2.VideoCapture(camera_source.url)
while (True):
    # Capture frame-by-frame
    ret, current_frame = capture.read()
    cv2.imshow('frame', current_frame)
    cv2.resizeWindow('frame', 1280, 640)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

1 个答案:

答案 0 :(得分:1)

您需要为Lambda添加主体apigateway.amazonaws.com的权限。

例如

aws lambda add-permission --function-name LambdaFunctionOverHttps \
--statement-id apigateway-prod-2 --action lambda:InvokeFunction \
--principal apigateway.amazonaws.com \
--source-arn "arn:aws:execute-api:$REGION:$ACCOUNT:$API/prod/POST/DynamoDBManager"

这里是add-permission API docs