Sharing IT Knowledge and Life – Chia sẻ kiến thức IT và đời sống

Wednesday, January 15, 2025

Các phần mềm phổ biến hỗ trợ thiết kế thời trang

Thiết kế thời trang luôn gắn liền với công nghệ. Từ bản phác thảo ý tưởng, bảng màu, họa tiết vải, rập (patterns), giác sơ đồ cho đến mô phỏng trang phục 3D, mỗi công đoạn đều có phần mềm chuyên dụng. Bài viết này giới thiệu các phần mềm tiêu biểu, chia theo nhóm chức năng và theo từng giai đoạn phát triển từ năm 2000 đến năm 2025.


1. Nhóm phần mềm đồ họa: phác thảo và minh họa thiết kế

Đây là nhóm đầu tiên nhà thiết kế tiếp cận, dùng để vẽ phác thảo (sketch), vẽ kỹ thuật (flat sketch), phối màu, thiết kế họa tiết in và trình bày bảng ý tưởng (moodboard).

1.1. Adobe Photoshop

  • Đặc điểm: Phần mềm xử lý ảnh raster, ra đời từ năm 1990 và trở thành chuẩn mực của ngành đồ họa.
  • Ứng dụng trong thời trang: Phối màu, xử lý ảnh mẫu, dựng moodboard, thiết kế họa tiết vải, vẽ minh họa thời trang bằng bút vẽ số, tạo lookbook và ảnh quảng bá bộ sưu tập.
  • Điểm mạnh: Hiệu ứng chất liệu và ánh sáng chân thực, hệ sinh thái plugin và tài nguyên rất lớn.

1.2. Adobe Illustrator

  • Đặc điểm: Phần mềm đồ họa vector, cho nét vẽ sắc nét và phóng to không bị vỡ hình.
  • Ứng dụng trong thời trang: Vẽ bản vẽ kỹ thuật (technical flat), đường may, chi tiết túi, cổ, tay áo, thiết kế họa tiết lặp (repeat pattern), logo, nhãn mác, tech pack.
  • Điểm mạnh: Là công cụ gần như bắt buộc để làm tech pack gửi nhà máy sản xuất. Từ năm 2013, Adobe chuyển sang mô hình thuê bao Creative Cloud.

1.3. CorelDRAW

  • Đặc điểm: Phần mềm đồ họa vector của Corel, ra đời từ năm 1989.
  • Ứng dụng trong thời trang: Vẽ mẫu thiết kế, thiết kế họa tiết, trình bày bản vẽ kỹ thuật.
  • Điểm mạnh: Giao diện thân thiện, rất phổ biến trong các xưởng may, cơ sở in ấn và thêu, đặc biệt ở các nước châu Á vào thập niên 2000.

1.4. Corel Painter (trước là MetaCreations Painter)

  • Đặc điểm: Phần mềm vẽ kỹ thuật số mô phỏng chất liệu truyền thống như màu nước, sơn dầu, chì, phấn, marker. Painter từng thuộc MetaCreations vào cuối thập niên 1990, sau đó được Corel tiếp quản vào đầu những năm 2000 và phát triển thành Corel Painter.
  • Ứng dụng trong thời trang: Vẽ minh họa thời trang (fashion illustration) mang phong cách vẽ tay, tạo hiệu ứng màu nước và marker rất tự nhiên.
  • Điểm mạnh: Cảm giác vẽ gần với giấy và bút thật, phù hợp với nhà thiết kế thích phong cách nghệ thuật.
Lưu ý: Từ khoảng năm 2015 trở đi, các ứng dụng vẽ trên máy tính bảng như Procreate (iPad) và Adobe Fresco được nhiều nhà thiết kế trẻ ưa chuộng để phác thảo nhanh.

2. Nhóm phần mềm CAD ngành may: rập, nhảy size và giác sơ đồ

Nhóm này chuyên về kỹ thuật, dùng cho khâu thiết kế rập và chuẩn bị sản xuất công nghiệp. Hai tên tuổi lớn nhất là Gerber và Lectra.

2.1. Gerber AccuMark

  • Hãng phát triển: Gerber Technology (Mỹ).
  • Chức năng chính: Thiết kế và chỉnh sửa rập (pattern making), nhảy size (grading), giác sơ đồ (marker making), tính định mức nguyên phụ liệu.
  • Điểm mạnh: Độ chính xác cao, được nhiều nhà máy may xuất khẩu lớn sử dụng, tích hợp với máy cắt tự động và hệ thống quản lý sản phẩm (PLM) của hãng.

2.2. Lectra

  • Hãng phát triển: Lectra (Pháp).
  • Các giải pháp tiêu biểu:
    • Modaris: thiết kế và chỉnh sửa rập 2D, mô phỏng 3D.
    • Diamino: giác sơ đồ tự động, tối ưu tiêu hao vải.
    • Kaledo: thiết kế họa tiết vải, dệt, dệt kim, phối màu và minh họa thiết kế.
  • Điểm mạnh: Giải pháp trọn gói từ sáng tạo đến sản xuất, được nhiều thương hiệu và tập đoàn thời trang lớn tin dùng, nhất là ở phân khúc cao cấp.

2.3. Các phần mềm CAD ngành may khác

Ngoài hai cái tên trên, nhiều xưởng và nhà máy còn sử dụng Optitex, Tukatech, Assyst, Gemini, Pad System, Richpeace... Mỗi phần mềm có thế mạnh riêng về giá thành, tính năng hoặc mức độ phổ biến theo khu vực.

3. Nhóm phần mềm mô phỏng 3D

3.1. Marvelous Designer / CLO 3D

  • Hãng phát triển: CLO Virtual Fashion (Hàn Quốc), ra mắt khoảng năm 2009–2010.
  • Đặc điểm: Cho phép ghép rập 2D thành trang phục 3D trên người mẫu ảo (avatar). Vải được mô phỏng theo vật lý: độ rũ, độ dày, độ co giãn, nếp gấp.
  • Phân biệt: Marvelous Designer hướng đến ngành giải trí (phim, game, hoạt hình). CLO 3D hướng đến ngành thời trang và sản xuất, hỗ trợ xuất rập, thử độ vừa vặn, trình diễn bộ sưu tập ảo.
  • Lợi ích: Giảm số lần may mẫu thật, tiết kiệm vải và chi phí, rút ngắn thời gian phát triển sản phẩm, góp phần thời trang bền vững.

3.2. Các phần mềm 3D khác

Browzwear (VStitcher), Style3D, Optitex 3D... cũng được dùng rộng rãi trong ngành may mặc xuất khẩu.

4. Nhóm phần mềm quản lý vòng đời sản phẩm (PLM)

Từ khoảng giữa thập niên 2010, các thương hiệu lớn chú trọng quản lý toàn bộ quy trình từ ý tưởng, tech pack, nhà cung cấp, chi phí đến sản xuất bằng các nền tảng PLM như Lectra Fashion PLM, Gerber YuniquePLM, Centric PLM... Nhờ đó dữ liệu thiết kế được đồng bộ giữa nhà thiết kế, bộ phận kỹ thuật và nhà máy.

5. Tổng quan phát triển từ năm 2000 đến 2025

Giai đoạn Đặc điểm nổi bật Phần mềm tiêu biểu
2000–2008 Số hóa quy trình 2D, phổ biến phần mềm đồ họa và CAD rập Photoshop, Illustrator, CorelDRAW, Painter, Gerber AccuMark, Lectra
2009–2015 Xuất hiện mô phỏng 3D, Adobe chuyển sang Creative Cloud Marvelous Designer, CLO 3D, Adobe CC
2016–2019 Phát triển PLM, thiết kế trên máy tính bảng, thời trang bền vững Procreate, Browzwear, PLM, CLO 3D
2020–2025 Thiết kế 3D phổ biến, mẫu ảo, tích hợp AI, thời trang số CLO 3D, Style3D, công cụ AI hỗ trợ ý tưởng và họa tiết

6. Nên học phần mềm nào?

  • Mới bắt đầu, thiên về sáng tạo: Photoshop và Illustrator là nền tảng gần như không thể thiếu.
  • Thích vẽ minh họa nghệ thuật: Corel Painter hoặc Procreate.
  • Muốn làm kỹ thuật, rập, sản xuất: Gerber AccuMark hoặc Lectra (Modaris, Diamino).
  • Muốn theo xu hướng mới: CLO 3D hoặc Marvelous Designer.
  • Trường đại học hoặc dạy nghề: CorelDRAW vẫn là phổ biến, đặc biệt ở những xưởng in vải thủ công.

Kết luận

Mỗi phần mềm đảm nhiệm một khâu riêng trong chuỗi thiết kế thời trang: Photoshop, Illustrator, CorelDRAW, Painter cho sáng tạo và trình bày; AccuMark, Lectra cho kỹ thuật và sản xuất; Marvelous Designer, CLO 3D cho mô phỏng 3D. Nhà thiết kế nên biết kết hợp nhiều công cụ để vừa giữ được tính nghệ thuật, vừa đáp ứng yêu cầu của sản xuất công nghiệp.

Monday, January 1, 2024

JPA cơ bản

Java Persistence API cơ bản

1. JPA là gì?

Java Persistence API (JPA) là đặc tả (specification) chuẩn của Java để ánh xạ đối tượng Java với các bảng trong cơ sở dữ liệu quan hệ (ORM) và để lưu trữ dữ liệu một cách bền vững (persistence). JPA ban đầu thuộc Java EE (Oracle) và hiện được phát triển bởi Eclipse Foundation với tên Jakarta Persistence.

JPA có Java Persistence Query Language (JPQL), một ngôn ngữ truy vấn hướng đối tượng, độc lập với từng loại database. Nhờ vậy, ứng dụng có thể đổi database (MySQL, PostgreSQL, Oracle...) mà không cần sửa code.

Lưu ý: JPA chỉ là đặc tả. Để chạy được cần một implementation (JPA provider).

Các JPA provider phổ biến

  • Hibernate (phổ biến nhất)
  • EclipseLink (reference implementation)
  • OpenJPA
  • DataNucleus (hỗ trợ cả JPA và JDO)

Ý tưởng chính: nếu chỉ dùng API chuẩn của JPA, bạn có thể thay đổi provider mà không sửa code. Tuy nhiên Hibernate còn cung cấp native API (HQL, Criteria của Hibernate, Session...) với nhiều tính năng vượt ngoài JPA, đổi lại bạn bị phụ thuộc vào Hibernate.

2. JPA và JDO

JDO (Java Data Objects) và JPA đều là đặc tả, không phải implementation, và đều là chuẩn persistence của Java.

JPAJDO
Datastore hỗ trợChỉ RDBMSMọi loại datastore (RDBMS, NoSQL, object DB...)
Mức độ phổ biếnRất caoThấp hơn
ImplementationHibernate, EclipseLink, OpenJPA...DataNucleus...

Hibernate không implement JDO. Nếu cần JDO, hãy tham khảo DataNucleus.

3. Lịch sử phát triển

Quá trình tiến hoá của các công nghệ persistence trong Java:

  1. JDBC: thao tác SQL trực tiếp
  2. Data Mapper (MyBatis...)
  3. EJB (Entity Bean)
  4. JDO
  5. JPA
    • JPA 1.0 (cùng EJB 3.0, 2006)
    • JPA 2.0 (2009)
    • JPA 2.1 (2013)
    • JPA 2.2 (2017)
    • Jakarta Persistence 3.0 (2020, đổi package sang jakarta.persistence)
    • Jakarta Persistence 3.1 (2022) và 3.2 (2024)

4. Cấu trúc của JPA

JPA gồm 4 phần:

  • The Java Persistence API: EntityManager, EntityManagerFactory, annotation...
  • The Criteria API: xây dựng truy vấn bằng code, an toàn kiểu (type-safe)
  • Query language (JPQL)
  • Object-relational mapping metadata: annotation hoặc XML (@Entity, @Table, @Column...)

5. Ví dụ nhanh

Entity

java
@Entity
@Table(name = "customers")
public class Customer {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @Column(nullable = false, length = 100)
    private String name;

    // constructor mặc định (bắt buộc), getter/setter
}

persistence.xml (đặt trong META-INF/)

xml
<persistence-unit name="demoPU" transaction-type="RESOURCE_LOCAL">
    <class>com.example.Customer</class>
    <properties>
        <property name="jakarta.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/demo"/>
        <property name="jakarta.persistence.jdbc.user" value="root"/>
        <property name="jakarta.persistence.jdbc.password" value="secret"/>
        <!-- Hibernate dialect, thường tự nhận diện ở bản mới -->
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
    </properties>
</persistence-unit>

Danh sách dialect: Hibernate Configuration (TutorialsPoint)

Dùng EntityManager (CRUD)

java
EntityManagerFactory emf = Persistence.createEntityManagerFactory("demoPU");
EntityManager em = emf.createEntityManager();

em.getTransaction().begin();
Customer c = new Customer();
c.setName("An");
em.persist(c);                         // Create
em.getTransaction().commit();

Customer found = em.find(Customer.class, c.getId());   // Read

em.getTransaction().begin();
found.setName("Binh");                 // Update (tự động flush khi commit)
em.getTransaction().commit();

em.getTransaction().begin();
em.remove(found);                      // Delete
em.getTransaction().commit();

em.close();
emf.close();

find() vs getReference()

  • find() truy vấn DB ngay và trả về entity (hoặc null nếu không có).
  • getReference() trả về một proxy lazy, chỉ truy vấn khi truy cập dữ liệu. Nếu không tồn tại sẽ ném EntityNotFoundException. Hữu ích khi chỉ cần tham chiếu khoá ngoại mà không cần tải toàn bộ entity.

6. Vòng đời của Entity

Trạng tháiMô tả
New / TransientVừa tạo bằng new, chưa gắn với persistence context
ManagedĐược quản lý bởi EntityManager, thay đổi sẽ tự được đồng bộ xuống DB
DetachedĐã tách khỏi persistence context (sau close(), detach())
RemovedĐã đánh dấu xoá, sẽ bị xoá khi commit

7. Ánh xạ quan hệ (Relationship Mapping)

4 loại quan hệ

  • @OneToOne
  • @ManyToOne
  • @OneToMany
  • @ManyToMany

Mỗi quan hệ có thể là một chiều (unidirectional) hoặc hai chiều (bidirectional), và có thể tải ngay (EAGER) hoặc theo yêu cầu (LAZY).

Mặc định: @OneToOne và @ManyToOne là EAGER, @OneToMany và @ManyToMany là LAZY.

Owning side và Inverse side

Mỗi quan hệ có hai phía:

  • Owning side: chịu trách nhiệm cập nhật quan hệ xuống database, thường là phía giữ khoá ngoại.
  • Inverse side: phía còn lại, ánh xạ ngược về owning side bằng thuộc tính mappedBy.

Nếu bạn quen Hibernate, mappedBy của JPA tương đương thuộc tính inverse của Hibernate: phía inverse sẽ bị bỏ qua khi cập nhật quan hệ.

java
@Entity
public class Order {
    @Id @GeneratedValue
    private Long id;

    // Inverse side
    @OneToMany(mappedBy = "order", cascade = CascadeType.ALL, orphanRemoval = true)
    private List<OrderItem> items = new ArrayList<>();
}

@Entity
public class OrderItem {
    @Id @GeneratedValue
    private Long id;

    // Owning side (giữ khoá ngoại order_id)
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "order_id")
    private Order order;
}

Cascade

CascadeType gồm PERSIST, MERGE, REMOVE, REFRESH, DETACH, ALL. Dùng để lan truyền thao tác từ entity cha sang entity con.

Embedded object và ElementCollection

  • @Embeddable / @Embedded / @EmbeddedId: nhúng một đối tượng giá trị (ví dụ Address) hoặc khoá chính tổ hợp. Xem JPA EmbeddedId example
  • @ElementCollection: lưu tập hợp các giá trị cơ bản hoặc embeddable. Xem ElementCollection (Wikibooks)

8. Truy vấn trong JPA

Có 3 cách truy vấn:

  1. Native query: SQL thuần
  2. JPQL (Java Persistence Query Language, SQL hướng đối tượng): Query, TypedQuery, @NamedQuery / @NamedQueries
  3. Criteria API: xây dựng truy vấn bằng code, động và type-safe
java
// JPQL với tham số (khuyến nghị, tránh SQL injection)
TypedQuery<Customer> q = em.createQuery(
    "SELECT c FROM Customer c WHERE c.name = :name", Customer.class);
q.setParameter("name", "An");
List<Customer> list = q.getResultList();

// Named Query
@Entity
@NamedQuery(name = "Customer.findByName",
            query = "SELECT c FROM Customer c WHERE c.name = :name")
public class Customer { ... }

em.createNamedQuery("Customer.findByName", Customer.class)
  .setParameter("name", "An")
  .getResultList();

// Criteria API
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Customer> cq = cb.createQuery(Customer.class);
Root<Customer> root = cq.from(Customer.class);
cq.select(root).where(cb.equal(root.get("name"), "An"));
List<Customer> result = em.createQuery(cq).getResultList();
  • Named Query là truy vấn tĩnh, được parse và kiểm tra cú pháp khi khởi động ứng dụng, dễ tái sử dụng.
  • Truy vấn động (dynamic) (JPQL hoặc native) được tạo lúc runtime.
  • Criteria API linh hoạt hơn và an toàn kiểu hơn khi cần xây dựng điều kiện động.
  • Luôn dùng parameter binding (:name, ?1) thay vì nối chuỗi để chống SQL injection.

9. Kế thừa (Inheritance)

JPA có 3 chiến lược ánh xạ kế thừa:

Chiến lượcMô tảƯu điểmNhược điểm
SINGLE_TABLE (mặc định)Cả hệ thống phân cấp lớp vào một bảng (kèm cột phân biệt DTYPE)Không cần JOIN, truy vấn nhanhNhiều cột NULL, không đặt được NOT NULL cho cột lớp con
JOINEDMỗi lớp một bảng, bảng con chỉ chứa cột riêng và join với bảng cha qua khoá chínhDữ liệu chuẩn hoá, không trùng lặpPhải JOIN nên truy vấn chậm hơn
TABLE_PER_CLASSMỗi lớp cụ thể một bảng chứa đầy đủ cột (kể cả cột kế thừa)Truy vấn lớp cụ thể không cần JOINDữ liệu chung bị lặp ở nhiều bảng, truy vấn đa hình dùng UNION; là tính năng tuỳ chọn trong spec

Ví dụ với JOINED, đặt annotation ở entity cha:

java
@Entity
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class Vehicle { ... }

@Entity
public class Car extends Vehicle { ... }

Ngoài ra có @MappedSuperclass: lớp cha chỉ để dùng chung các trường (ví dụ id, createdAt), không phải entity và không có bảng riêng.

Ghi chú (legacy) về Google App Engine: với Datastore cũ dùng DataNucleus, JOINED và SINGLE_TABLE không được hỗ trợ; TABLE_PER_CLASS và MAPPED_SUPERCLASS hoạt động như mô tả trong tài liệu DataNucleus.

10. Một số lưu ý thực tế (Best practices)

  • N+1 problem: duyệt quan hệ LAZY trong vòng lặp có thể sinh rất nhiều câu SQL. Khắc phục bằng JOIN FETCH, @EntityGraph hoặc batch fetching.
  • Ưu tiên FetchType.LAZY cho mọi quan hệ, chỉ dùng EAGER khi thật sự cần.
  • Luôn có constructor mặc định (không tham số) cho entity, và override equals() / hashCode() cẩn thận.
  • Với quan hệ hai chiều, hãy đồng bộ cả hai phía bằng phương thức tiện ích (ví dụ order.addItem(item)).
  • Đừng dùng hbm2ddl.auto=update trên production; hãy dùng công cụ migration như Flyway hoặc Liquibase.
  • Trong Spring, dùng Spring Data JPA (JpaRepository) để giảm code lặp, nhưng vẫn cần hiểu JPA bên dưới.

Reference:

Sunday, September 12, 2021

Saturday, August 21, 2021

The Competition Among Frontend Frameworks

Frontend technologies for desktop and responsive web applications can be categorized into five main types:

  • Angular
  • ReactJS / Next.js
  • Vue.js
  • Classic Web (HTML, CSS, jQuery, Thymeleaf, ASP.NET)
  • Flutter Web

These technologies coexist in the market, competing with and complementing one another.

Monday, July 26, 2021

Creating a Batch Service

To start from scratch, move on to Starting with Spring Initializr.

To skip the basics, do the following:

When you finish, you can check your results against the code in gs-batch-processing/complete.

Business Data

Typically, your customer or a business analyst supplies a spreadsheet. For this simple example, you can find some made-up data in src/main/resources/sample-data.csv:

Jill,Doe
Joe,Doe
Justin,Doe
Jane,Doe
John,Doe

This spreadsheet contains a first name and a last name on each row, separated by a comma. This is a fairly common pattern that Spring can handle without customization.

Spring batch introduction

Spring Batch is a lightweight, comprehensive batch framework designed to enable the development of robust batch applications vital for the daily operations of enterprise systems. Spring Batch builds upon the characteristics of the Spring Framework that people have come to expect (productivity, POJO-based development approach, and general ease of use), while making it easy for developers to access and leverage more advance enterprise services when necessary. Spring Batch is not a scheduling framework. There are many good enterprise schedulers (such as Quartz, Tivoli, Control-M, etc.) available in both the commercial and open source spaces. It is intended to work in conjunction with a scheduler, not replace a scheduler. 

Spring Batch is also a minimalistic framework to run batch processing applications. It provides reusable functions that are essential in processing large volumes of records, including logging/tracing, transaction management, job processing statistics, job restart, skip, and resource management. It also provides more advanced technical services and features that will enable extremely high-volume and high-performance batch jobs through optimization and partitioning techniques. Simple as well as complex, high-volume batch jobs can leverage the framework in a highly scalable manner to process significant volumes of information.

Spring Batch provides reusable functions that are essential in processing large volumes of records, including logging/tracing, transaction management, job processing statistics, job restart, skip, and resource management. It also provides more advanced technical services and features that enable extremely high-volume and high performance batch jobs through optimization and partitioning techniques. Spring Batch can be used in both simple use cases (such as reading a file into a database or running a stored procedure) as well as complex, high volume use cases (such as moving high volumes of data between databases, transforming it, and so on). High-volume batch jobs can leverage the framework in a highly scalable manner to process significant volumes of information.

Saturday, July 24, 2021

What is backbase

What are Digital Banking Platforms (DBP)?

A digital banking platform (DBP) enables a bank to begin the transformational process of becoming a truly digital bank that is ecosystem-centric. A DBP also enables banks to achieve business optimization. However, that is not the end state. For banks seeking only business optimization as the goal of their digital banking strategy, a digital banking multichannel solution will meet those needs.

Installation mdbootstrap 5

Install MDB (Material Design for Bootstrap) UI Kit

Step 1

Download the package

Step 2

Unzip the downloaded package and open it in your code editor.

Step 3

Open the Dreamweaver editor and create an HTML site.

Find a template site, copy an index.html file into your project and compose your website. And yes, it's that simple!

Importing CSS file

To import the MDB stylesheet, please use the following syntax:

<!-- Font Awesome -->
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.11.2/css/all.css" />

<!-- Google Fonts Roboto -->
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700&display=swap" />

<!-- MDB -->
<link rel="stylesheet" href="css/mdb.min.css" />

Importing JS file

<script src="js/mdb.min.js"></script>

Run

Click the index.html file to open it in your browser, and it works!

Source code

IntegratedMaterialDesignAdminDemo

Reference document

https://mdbootstrap.com/docs/standard/getting-started/installation/

Wednesday, March 3, 2021

Amazon SQS as an Event Source to AWS Lambda 

 What is Amazon Simple Queue Service?

Amazon Simple Queue Service (Amazon SQS) offers a secure, durable, and available hosted queue that lets you integrate and decouple distributed software systems and components (send, receive, and delete a message). Amazon SQS offers common constructs such as dead-letter queues and cost allocation tags. It provides a generic web services API that you can access using any programming language that the AWS SDK supports.

Amazon SQS supports both standard and FIFO queues. For more information, see Queue types.

In AWS, SQS can be an event source to Lambda, all that heavy lifting of managing message polling and deleting has been offloaded to the Lambda service, which is now your SQS consumer. It should be called Lambda SQS Consumer Service.

 Lambda is doing the scaling of consumers of YOUR SQS queue for messages, receiving messages, and passing those messages to your Lambda function, and then deleting those messages when your Lambda function successfully handles the message(s) received. This is all explained in more detail here.

Below is a nice visual of what’s going on with this integration.


If you already know enough about SQS as an event source and how the AWS Lambda integration works, skip the preamble and move onto Get Started using the included end-to-end CloudFormation template and then come back for a deeper dive.

Get Started — Backend

I created a CloudFormation template that will provision: 

  1. A standard SQS queue.
  2. A dead letter queue.
  3. AWS Lambda function for handling messages.
  4. The event source mapping.
  5. Lambda execution permissions to SQS and SNS for sending SMS text message. 

Click on the template to launch the CloudFormation console to begin building your stack. The template defaults to the US West Oregon region (us-west-2).

Once the stack completes, you can now test the setup as follows:

1. In the Amazon SQS console, send messages to the queue.

2. AWS Lambda polls the queue and when it detects new messages, it invokes your Lambda function by passing in the event data from the queue.

3. Your function executes and creates logs in Amazon CloudWatch. You can verify the logs reported in the Amazon CloudWatch Logs console.

To really see the value of SQS, checkout my sample iOS Swift application (you can download it from GitHub here) that demonstrates single and batch messages.

AWS Lambda service (not your Lambda function, but a Lambda SQS long-poll service running on your behalf) polls your SQS queue continually for incoming messages. When a message arrives, it receives the message(s) and then invokes your Lambda function by passing the message(s) as a parameter.

Configuring a queue to trigger an AWS Lambda function (console)

You can use an AWS Lambda function to process messages in an Amazon SQS queue. Lambda polls the queue and invokes your Lambda function synchronously with an event that contains queue messages. You can specify another queue to act as a dead-letter queue for messages that your Lambda function can't process. 

A Lambda function can process items from multiple queues (using one Lambda event source for each queue). You can use the same queue with multiple Lambda functions. 

If you associate an encrypted queue with a Lambda function but Lambda doesn't poll for messages, add the kms:Decrypt permission to your Lambda execution role. 

Note the following restrictions:

Your queue and the Lambda function must be in the same AWS Region.

An encrypted queue that uses the default key (AWS managed CMK for Amazon SQS) cannot invoke a Lambda function in a different AWS account. 

For information about implementing the Lambda function, see Using AWS Lambda with Amazon SQS in the AWS Lambda Developer Guide. 

Prerequisites

To configure Lambda function triggers, you must meet the following requirements:

If you use an IAM user, your Amazon SQS role must include the following permissions:

lambda:CreateEventSourceMapping

lambda:ListEventSourceMappings

lambda:ListFunctions

The Lambda execution role must include the following permissions:

sqs:DeleteMessage

sqs:GetQueueAttributes

sqs:ReceiveMessage

If you associate an encrypted queue with a Lambda function, add the kms:Decrypt permission to the Lambda execution role. 

For more information, see Overview of managing access in Amazon SQS. 

To configure a queue to trigger a Lambda function (console) 

1. Open the Amazon SQS console at https://console.aws.amazon.com/sqs/

In the navigation pane, choose Queues. 

On the Queues page, choose the queue to configure. 

On the queue's page, choose the Lambda triggers tab. 

On the Lambda triggers page, choose a Lambda trigger. 

If the list doesn't include the Lambda trigger that you need, choose Configure Lambda function trigger. Enter the Amazon Resource Name (ARN) of the Lambda function or choose an existing resource. Then choose Save. 

Choose Save. The console saves the configuration and displays the Details page for the queue. 

On the Details page, the Lambda triggers tab displays the Lambda function and its status. It takes approximately 1 minute for the Lambda function to become associated with your queue. 

To verify the results of the configuration, send a message to your queue and then view the triggered Lambda function in the Lambda console. 



Source:

Tuesday, March 2, 2021

Beginning Amazon DynamoDB

What Is Amazon DynamoDB?

Amazon DynamoDB is a fully managed NoSQL database service that provides fast and predictable performance with seamless scalability. 

NoSQL is a term used to describe nonrelational database systems that are highly available, scalable, and optimized for high performance. Instead of the relational model, NoSQL databases (like DynamoDB) use alternate models for data management, such as key-value pairs or document storage. For more information, see http://aws.amazon.com/nosql.

POPULAR | PHỔ BIẾN

TAGS

VIEWS