Share
Embed
O Canivete Suíço para o Desenvolvimento Serverless
Ana Cunha
October 07, 2020
Transcript
49 slides
-
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Ana Cunha Developer Advocate O Canivete Suíço para o Desenvolvimento Serverless -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Arquiteturas Tradicionais -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Web Service Service Cliente HTTP -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Web Service na Nuvem Instância EC2 Banco de Dados -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Banco de Dados Web Service na Nuvem – Escalando Verticalmente Instância EC2 -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Banco de Dados Web Service na Nuvem – Escalando Horizontalmente Elastic Load Balancer -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Banco de Dados Web Service na Nuvem – Auto Scaling Elastic Load Balancer Auto Scaling Group -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Banco de Dados Web Service na Nuvem – Alta Disponibilidade Elastic Load Balancer Auto Scaling Group Availability Zone A Availability Zone B -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Gerenciamento da Aplicação • Aplicação + Código • Lógica de Negócio • Provisionamento de Servidores • Sistemas Operacionais • Patches • Políticas de Escala • Planejamento de Capacidade • Disponibilidade Core Business Infraestrutura -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Serverless -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Componentes Essenciais Requisição Lógica de Negócio Outros Serviços -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Componentes Essenciais Outros Serviços Evento Código -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. AWS Lambda – Componentes Serverless Outros Serviços Evento Event Source Handler AWS Lambda Function Amazon SNS Amazon S3 Amazon DynamoDB -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Serverless ü Sem gerenciamento de servidores -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Serverless ü Sem gerenciamento de servidores ü Escalabilidade flexível -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Serverless ü Sem gerenciamento de servidores ü Escalabilidade flexível ü Pagamento pelo valor -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Serverless ü Sem gerenciamento de servidores ü Escalabilidade flexível ü Alta disponibilidade ü Pagamento pelo valor -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Serverless Amplia os Benefícios da Nuvem Servidores físicos em data centers Servidores virtuais na nuvem Serverless -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Desenvolvimento Serverless Boas Práticas -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Produção Desenvolvimento e deploy seguindo boas práticas. Boas Práticas de Desenvolvimento São as Mesmas Experimentação Uso do Console de Gerenciamento da AWS para criação, teste e deploy. IDE -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Handler handler(event, context) Separação de Responsabilidades • Toda função Lambda tem um método handler • Processamento de eventos • Funcionalidade separada em múltiplas classes e funções -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Separação de Responsabilidades Handler • Configuração da função • Código específico para Lambda • Sem lógica de negócio Handler Controller Service -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Separação de Responsabilidades Controller • Processamento do evento • Lógica de Negócio Handler Controller Service -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Separação de Responsabilidades Service • Abstrações • Integrações externas Service Handler Controller -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Execution Context • Ambiente de runtime temporário • Baseado na configuração de memória e timeout definidas • Recursos necessários para executar a função Lambda • Carrega e inicializa as dependências da função • “Bootstrapping” do runtime • Reutilizado por algum tempo pelas próximas execuções da função -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Dependências Cold Start Warm Start Download código, inicialização Execution Context Bootstrap do runtime Iniciar o código Bootstrap • Minimizar dependências • Considerar tempo de inicialização • Outras dependências e frameworks -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Suporte Serverless para Frameworks Conhecidos AWS Serverless Java Container AWS Serverless Express Zappa -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Desenvolvimento Serverless Ferramentas -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Ferramentas Conhecidas • Sistema de Controle de Versão • IDE • Build • Deploy Novas • Framework para desenvolvimento de aplicações Serverless -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Serverless Application Framework Código Binário S3 Bucket Arquivo ZIP AWS Lambda Criação Build Package Deploy IDE + Ferramenta de Build Serverless Application Framework -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Etapas de Deploy 1. Build 2. ZIP 3. Upload para Amazon S3 4. Criar atualizar roles 5. Criar função Lambda 6. Criar API REST 7. Criar recurso 8. Criar método 9. Criar tabela 10. Configurar integrações Deploy -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. AWS CloudFormation • Infraestrutura como código • Definição dos recursos que precisam ser criados • Provisionamento automatizado e replicável • Código = versionamento + revisão + testes -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Serverless Application Model (SAM) -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. SAM • Framework para construir aplicações serverless • Escreva com YAML • Deploy com AWS CloudFomration • Open Source • https://github.com/awslabs/serve rless-application-model -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. SAM SAM Templates • Infraestrutura como código • Aplicações Serverless • Sintaxe abreviada • Definir recursos e event sources SAM CLI • Conjunto de ferramentas • Desenvolvimento local • Debugging • Build, package, deploy -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. SAM Template AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Resources: GetHtmlFunction: Type: AWS::Serverless::Function Properties: CodeUri: ./src Handler: index.gethtml Runtime: nodejs12.x Policies: AmazonDynamoDBReadOnlyAccess Events: Api: Type: Api Properties: Path: /{proxy+} Method: ANY ListTable: Type: AWS::Serverless::SimpleTable -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. SAM Serverless Resources AWS::Serverless::Function AWS::Serverless::Api AWS::Serverless::HttpApi AWS::Serverless::SimpleTable AWS::Serverless::LayerVersion AWS::Serverless::Application AWS::Serverless::StateMachine -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. SAM CLI sam init -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. SAM CLI sam init sam build -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. SAM CLI sam init sam build sam deploy --guided -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. SAM CLI sam init sam build sam deploy --guided # Host API locally sam local start-api -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. SAM CLI sam init sam build sam deploy --guided # Directly invoke function sam local invoke -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Desenvolvimento Serverless Sistemas de Controle de Versão -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Repositórios de Código Um para cada função Lambda Um para todas funções Lamba -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Repositórios de Código Nível de Serviços -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Serviços Service Uma ou mais funções, serviços e recursos AWS Template Repositório -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Desenvolvimento Serverless Ambientes de Desenvolvimento Integrado (IDE) -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. AWS Cloud9 • Criação • Execução • Debug • Deploy -
© 2020, Amazon Web Services, Inc. or its Affiliates. All
rights reserved. Obrigada! Ana Cunha @mcunhaana analuizacunha